Giter VIP home page Giter VIP logo

hexo-abbrlink's Introduction

hexo-abbrlink

npm npm npm

A Hexo plugin to generate static post link based on title and data in the post front.

This plugin supports .textbundle -- a file format contents markdown and its assets. Actually, .textbundle file is a folder which shows like a file in Finder on macOS.

Suggest

https://github.com/rozbo/hexo-abbrlink2, supports the orderly growth of ID is beta now. The working principle of hexo-abbrlink2 is different from this plug-in, not as an upgraded version of this plugin, they are different individuals. But hexo-abbrlink2 is compatible with the previous configuration of this plugin. As a supplement to this plugin, use it only when you really need an orderly growing id.

How to install

Add plugin to Hexo:

npm install hexo-abbrlink --save

Modify permalink in config.yml file:

permalink: posts/:abbrlink/ 
# or
permalink: posts/:abbrlink.html

There are two settings:

alg -- Algorithm (currently support crc16 and crc32, which crc16 is default)
rep -- Represent (the generated link could be presented in hex or dec value)
# abbrlink config
abbrlink:
  alg: crc32      #support crc16(default) and crc32
  rep: hex        #support dec(default) and hex
  drafts: false   #(true)Process draft,(false)Do not process draft. false(default) 
  # Generate categories from directory-tree
  # depth: the max_depth of directory-tree you want to generate, should > 0
  auto_category:
     enable: true  #true(default)
     depth:        #3(default)
     over_write: false 
  auto_title: false #enable auto title, it can auto fill the title by path
  auto_date: false #enable auto date, it can auto fill the date by time today
  force: false #enable force mode,in this mode, the plugin will ignore the cache, and calc the abbrlink for every post even it already had abbrlink. This only updates abbrlink rather than other front variables.

Sample

The generated link will look like the following:

crc16 & hex
https://post.zz173.com/posts/66c8.html

crc16 & dec
https://post.zz173.com/posts/65535.html
crc32 & hex
https://post.zz173.com/posts/8ddf18fb.html

crc32 & dec
https://post.zz173.com/posts/1690090958.html

Limitation

[fixed] Maximum number of posts is 65535 for crc16. (now, if a abbrlink already exist, it will change another one and try again and again...)

More info

see this(Chinese)

ThanksFor

NoahDragon

Sponsor

The project is develop by JetBrains Ide

hexo-abbrlink's People

Contributors

driftcrow avatar hyliang96 avatar kumannn avatar noahdragon avatar ohroy avatar xu-song avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hexo-abbrlink's Issues

关于标签链接

大佬,我现在只有文章不是中文的,标签页和分类页面怎么也让他变成不是中文呀?求帮助。

cannot deploy with Vercel

image
The error occur when deploying Hexo using Vercel with abbrlink plugin.
cannot figure out the solution atm

Something wrong when I don't set drafts and auto_category

I used this plugin a long time ago.

But there was an error during my most recent repository code commit.

FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'enable' of undefined
    at Hexo.logic (/Users/ryoma/Documents/write/wiki/node_modules/hexo-abbrlink/lib/logic.js:59:44)
    at Hexo.tryCatcher (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/util.js:16:23)
    at Hexo.<anonymous> (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/method.js:15:34)
    at /Users/ryoma/Documents/write/wiki/node_modules/hexo/lib/extend/filter.js:62:52
    at tryCatcher (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/ryoma/Documents/write/wiki/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

This BUG wasted two days of my time.

Now I've found out why, but only because I didn't set up options for this plugin!

I don't understand if this is a flaw in Hexo or a flaw in the plug-in, can't the plug-in itself set its own default value when judging, this kind of upgrade will bring trouble to most plug-in users, I hope to be able to fix it.

我很久之前就使用这个插件了,但最近一次我提交仓库代码的过程中出现了错误(如上)。
因为报错不明显,这个 BUG 浪费了我两天的时间去排查,最终才发现是因为我没有给这个插件新增的两个选项设置默认值!

我不明白这是 Hexo 的缺陷还是插件的缺陷,难道插件本身不能在判断的时候自己设置默认值嘛,这种升级会给大部分插件使用者带来困扰,希望能够修改一下。

序列增长具有随机性

请问插件生成的固定链接可以做到有序增长么,如20,21,23,... ,1427,1428这样;

或者有何其他方案可以实现上述功能。

travis 持续集成出错

出错信息如下,uninstall abbrlink就正常了

INFO Start processing
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'enable' of undefined
at Hexo.logic (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_hexo-abbrlink@2.1.5@hexo-abbrlink/lib/logic.js:59:44)
at Hexo.tryCatcher (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/util.js:16:23)
at Hexo. (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/method.js:15:34)
at Promise.each.filter (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_hexo@3.9.0@hexo/lib/extend/filter.js:60:50)
at tryCatcher (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/util.js:16:23)
at Object.gotValue (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/reduce.js:166:18)
at Object.gotAccum (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/reduce.js:155:25)
at Object.tryCatcher (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/async.js:93:12)
at _drainQueue (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/async.js:86:9)
at Async._drainQueues (/home/travis/build/kikyou93/kikyou93.github.io/node_modules/_bluebird@3.7.2@bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate]

文章内生成了abbrlink但是链接异常

有一篇博文的链接生成为了:https://.../posts/Infinity/
我检查了md文件,内部是生成了abbrlink的(2e876344)
目前只发现这一篇博文除了问题,其它都正常

有关当下版本启用post_asset_folder后与abbrlink插件冲突解决方案

之前有几个issues已经提到该问题,但由于hexo更新,hexo-asset-image插件集成到hexo-renderer-marked

粗略的看了下代码,确实与abbrlink插件无关。于是硬着头皮研究了好久,现附解决方案。

node_modules\hexo\lib\models\post_asset.js目录中

改动1:

return join(post.path.replace(/\.html?$/, ''), this.slug);

改为:

return join(dirname(post.path), post.slug, this.slug);

改动2:

const { join} = require('path');

改为

const { join, dirname } = require('path');

本想写个Scripts优雅地解决,尝试了很久都无法实现,只能改hexo的代码。希望后来者有人能研究出来。

不建议强行重写 .md 源文件

看了一下实现,其中把abbrlink写入到了.md文件中,同时也改动其他文本格式(比如CRLF与LF之间的替换 )。

建议:

  • 与hexo动态交互,而不是把link写入到md静态文件
  • link的复用可以采用独立的数据文件,不侵入源文件

当然重写有很多好处,但是觉得不够优雅

菜鸟愚见,逃

点击博文阅读变成了下载

hexo g出现: (node:29767) [DEP0061] DeprecationWarning: fs.SyncWriteStream is deprecated.

node_modules/hexo-abbrlink/node_modules/hexo-fs/lib/fs.js:718export.SyncWriteStrem = fs.SyncWriteStream;注释掉之后,警告没有了,但是博文url为:https://www.domain/posts/7930,没有.html后缀,并且没有crc32 & hex输出;
注:我在站点配置文件中添加了:

abbrlink:
  alg: crc32
  rep: hex

hexo s运行之后,在首页中点击文章Read more,原本是进入文章页面阅读,现在变成了下载
version info:

hexo: 3.3.8
node: 8.2.1
npm: 5.3.0

基于该插件,我二度开发了一个小插件

您的这个插件的确是很棒!
不过我发现,在我使用的时候,他只会针对没有设置layout值的博客以及值为post的博客。
因为我个人博客的布局较多,所以基于该插件,我开发了一个小插件,命名为hexo-abbrlink3
新特性为可以对指定布局进行应用或者是不进行应用。
项目链接在这里:https://github.com/Keen-King/hexo-abbrlink3
期待与您的进一步交流。
联系邮箱:[email protected]

几条建议

第一,CRC16或者32都有重复的可能,如果有重复,应该要在控制台提示到用户。仅仅重新分配的话,如果新写的文章和以前的重复且将以前文章的链接修改了,那么原来存在的指向该文章的链接都会出错,且用户并不知道。

第二,说明文档中指出crc16的重复概率是1/65536,但多篇文章全都不一样的概率不能这么算。文章数量到大约根号级别,即256篇文章的时候,重复概率已经很大了(40%)。所以建议还是使用CRC32。如果嫌8个字符的hex表示长的话,可以考虑将Int.toString(16)改成toString(36) (最大只能填36),这样可以包括所有小写和数字,大约可以省下2个字符…… 甚至可以自己写个函数把大写字母再加入(这个就不展开了)。

第三,其实CRC32之类的hash不是唯一选择,对于字符串的情形我们有一个比较通用的hash方法,见Generate a Hash from string in Javascript。最佳答案给出的代码也是返回一个32-bit的整数,和CRC32的范围相同。

String.prototype.hashCode = function() {
  var hash = 0, i, chr;
  if (this.length === 0) return hash;
  for (i = 0; i < this.length; i++) {
    chr   = this.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};

第四,蛮多人问undefined的问题的,考虑在说明中加入一下hexo clean

图片无法显示

安装hexo-abbrlink插件后,更改了原文件的图片链接,导致无法显示

非常感谢作者,但是当有图片存在时,有bug

非常感谢作者!!
我同时使用了hexo-asset-image和你的hexo-abbrlink,这2个插件对我帮助很大

hexo-asset-image的逻辑大概如下

  • hexo n title时,会在_post下新建title.md文件和同名的title文件夹
  • 编辑md时,如果需要插入图片,我们可以手动拷贝文件到title文件夹中
  • hexo g时,会自动拷贝同名文件夹到public恰当位置

但是用了hexo-abbrlink后,这个机制被破坏了
例如我新建了一篇测试.md,而hexo-abbrlink把它url转为13432.html,那么在拷贝图片时,会拷贝到13432文件夹中。而md文档转为html文件时,用的相对路径还是类似"测试/1.png",导致图片全部显示失败

能否在拷贝同名文件夹时,不要转名字,保留原始名字,这样方便存放图片,非常感谢!!

关于 hexo-abbrlink 和 hexo-asset-image 同时使用的图片显示问题

作者的插件写的非常棒,但是还是针对于 和 hexo-asset-image 同时使用的问 带给人非常大的困扰,对于一个刚刚接触 hexo的新人,原谅我实在没有看懂其他提问者的解决方式,希望作者能不能优化一下呢?
另外就是,如何做到关闭你的插件呢?我尝试删除 文章 头部 abbrlink: 属性和 修改 permalink: posts/:abbrlink/ 但是,abbrlink: 依然会重新生成,并且导致文章目录和内容错乱,能否做到当我使用了hexo-asset-image插件时,能够在hexo配置文件_config.yml中实现关闭 hexo-abbrlink插件呢?
ps: 我临时的解决让图片显示的方式是:在_posts文件下建立一个和文章abbrlink: 属性名字相同的文件夹,将图片放在这个文件夹中,修改图片的地址到这个文件下图片就能重新显示了,但是这个方法需要我每建一篇新的文章需要建立一个以文章abbrlink: 属性 为名字的问件夹,所以希望作者能针对于此做出优化,另外,如果实在不能改变,也希望作者在介绍中明确阐述,不能和hexo-asset-image 插件同时使用

auto_category配置项关闭失效

var opt_AutoCategoryEnable =
      this.config.abbrlink &&
      this.config.abbrlink.auto_category &&
       this.config.abbrlink.auto_category.enable
       ? this.config.abbrlink.auto_category.enable
       : true;

这部分代码应该是去判断是否用户设置了自动分类,否则默认为true
但是当用户设置了false时,这个判断由于false的存在还是false,导致最终依旧不会取到用户设置的值,进而设置false失效,使用过程中总会去生成文章分类。。造成原本写好的分类被改变
因此可以改为:

var opt_AutoCategoryEnable =
      this.config.abbrlink &&
      this.config.abbrlink.auto_category &&
      this.config.abbrlink.auto_category.enable != null
      ? this.config.abbrlink.auto_category.enable
      : true;

这样应该可以了

連結成功生成後,本地預覽、上傳後開起來一片空白,

大神你好,小弟不才,頭一次接觸 hexo ,也不太會寫碼

按照您給的方法後添加配置:

permalink: posts/:abbrlink.html
# abbrlink config
abbrlink:
  alg: crc32  # 算法:crc16(default) and crc32
  rep: hex    # 进制:dec(default) and hex 

生成連結開啟後卻是一片空白,檢查本地的 deploy.git\posts ,有文章檔案,但裡面一片空白,沒有任何程式碼,在網路上爬了許久,仍找不到解決辦法,故上來請教。

不曉得視插件的問題,還是其他問題呢?

還請多多擔待,謝謝您!

采用该插件后,文章Front-matter permalink 貌似就失效了

大佬感谢您的付出为我们贡献了一个优秀的永链解决方案,但是貌似使用这个插件后,每篇文章都会使用abbrlink作为链接地址。我现在有这么个需求,需要给博客添加一个“关于”页面,链接为/about;但是我在Markdown文件的Front-matter部分添加permalink: /about,但是这样做起不到任何作用(通过/about访问不到页面)。

使用此插件之后,图片显示不正确

请问如何访问资源文件夹中的图片呢?我把图片路径改为[abbrlink/文件名]之后可以正常访问,但想问问有计划支持相对直接用文件名的图片么?

有冲突,不知有办法解决 吗?

首先,你的这插件很好,很利于SEO。
但是,另一款插件: HEXO-自动分类 也是我喜欢用的,它是按文件目录结构自动生成分类的。

你们这2款插件都是读写 Front-matter 的数据。
现在,有个问题,如果同时启用这2个插件,会导致,你的这个插件无法向 md 文件里写入 abbrlink 属性。
而且,在 hexo s 运行下,会死循环似得,执行插件的动作,对随机某个md文件。

不知道有没有办法,兼容这2个插件呢?

hexo-abbrlink : 利于SEO
hexo-auto-category : 方便管理分类

按理来说,这2个插件都可用的啊,因为最终生成的是由 permalink 属性决定的。

启用hexo-abbrlike插件后会修改图片存储路径,是否有自动化的解决方案?

在使用插件之前在文章中嵌入图片语法如下

![](/hexo部署教程/02.jpg)

生成静态页面后images存储路径不变

使用插件后
生成静态页面的images存储路径变为了

![](/9f2323d4/02.jpg)

导致原来写的文章都找不到images,导致线上失败
问有没有比较好的解决方案避免这个问题
不知道有没有表达清楚 我的qq 1455975151

文章返回404

把_config.yml中 permalink: year/:month/:day/:title/ 改为permalink: year/:month/:day/:addrlink/后,文章返回404,这是为什么。

安装好无发生成新的链接

按照你的教程安装后,在页面上无法生成新的post代码。
文章的超链接指向的是: undefined

修改配置后,我通过下面的命令来生成新的页面。

hexo g
hexo d

重新生成链接

我生成一个文章的时候,有时候因为1)文章名字不合法(例如包含:在windowns系统),2)修改了文章名字,这样文章就不能生成AbbrLink链接。请问怎样手动重新生成?

请问能否对原链接进行自动重定向呢?

如题,例如原本没有使用 hexo-abbrlink 之前,生成的文章已经存在了很长的时间,现在使用了之后链接全部发生了变化,能否实现在访问原页面时自动重定向短链接呢?ヾ(@^▽^@)ノ

生成的链接为null

如题, 生成的不是 undefined, 而是 null.
步骤就是 hexo clean 然后hexo g .
之前 Hexo 3.8.0 的版本没问题, 不知道是不是升级到 4.2.0 的版本后的冲突.

image

post/undefined

遇到了个问题,按照你的步骤,对应的内容显示post/undefined
这是我的源内容,
permalink: posts/:abbrlink/
permalink_defaults:

abbrlink config

abbrlink:
alg: crc32 # 算法:crc16(default) and crc32
rep: hex # 进制:dec(default) and hex
已执行安装:npm install hexo-abbrlink --save

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.