npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexo-unique-post-path

v1.0.4

Published

This plug-in helps Hexo create new posts with unique auto-generated paths.

Downloads

32

Readme

hexo-unique-post-path

NPM Version LICENSE Build Status Coverage Status dependencies Status devDependencies Status

This plug-in helps Hexo create new posts with unique auto-generated paths.

Just like this.

$ hexo new2

INFO  Created: ./source/_posts/ck20kqmij0001ieyn4es62xh7.md

Installation

npm install --save hexo-unique-post-path

Usages

There are tree ways to use this plug-in to create new posts with unique auto-generated paths.

1. Use hexo new2 command

hexo new2 [layout] [title]

e.g.

$ hexo new2 "Hello World!"

INFO  Created: ./source/_posts/ck2c0zo1y0001gyyn5c2ma96m.md

$ hexo new2

INFO  Created: ./source/_posts/ck20kqmij0001ieyn4es62xh7.md

The title argument can be omitted and its default value is ' '.

You can define the default value of title in the _config.yml file.

#_cofig.yml

+ unique_post_path:
+   title_default: "new post"

You can define the path generating algorithm in the _config.yml file. e.g.

#_cofig.yml

+ unique_post_path:
+   type: nanoid
+   size: 20

or

#_cofig.yml

+ unique_post_path:
+   type: date-seq
+   size: 2
+   prefix: YYYYMMDD

Available type:

type | length | character set |options | default | description --- | --- | --- | --- | --- | --- cuid (default) | 25 | a-z0-9, start with c | | | use cuid() generated string. e.g. ck2bi7fxf00013ryng5jr1rer cuid-slug | 7-10 | a-z0-9 | | | use cuid.slug() generated string. e.g. xh23npi nanoid | 21 | A-Za-z0-9_- | size | 21 | use nanoid() generated string. e.g. EwUTt2eoka-oEV5kf-o0O nanoid-simple | 24 | a-z0-9 | size | 24 | use nanoid/generate generated string. e.g. pfldm3gg8h9psydphotqe71d nanoid-lowercase | 26 | a-z | size | 26 | use nanoid/generate generated string. e.g. jsjxoibprplrdoitjmppotjrnm seq | 1~ | 0-9 | sizestart | 11 | 1, 2, 3,...001, 002, 003,... prefix-seq | 1~ | A-Za-z0-9_- | sizestartprefix | 11<none> | items-1, items-2, items-3,...items-001, items-002, items-003,... date-seq | 1~ | A-Za-z0-9_- | sizestartprefix (*) | 21YYYYMMDD | 2019102901, 2019102902, 2019103001, ...2019-10-29-001, 2019-10-29-002, 2019-10-30-001,... latin | 1~ | A-Za-z0-9_- | separatorlowercase | -true | the argument title is required. "你好, World!" => ni-hao-world"안녕하세요, 세계" => annyeonghaseyo-segye

Sample of valid prefix option for date-seq:

YYYYMMDD (default)
YYYY-MM-DD-
YYMMDD-
YYYYMM
YYYY

You can add your own path generating algorithm by define Custom functions.

If the layout is page, or if --path, -p or --slug, -s option is provided, hexo new2 works same as hexo new.

2. Use hexo new command with unique_post_path configuration

Add unique_post_path options to the _config.yml file.

#_cofig.yml

+ unique_post_path:
+   auto: true

Then use new command as before.

$ hexo new "My New Post"

INFO  Created: ./source/_posts/ck20kqmij0001ieyn4es62xh7.md

3. Use hexo new command with --type option

$ hexo new "Hello World!" --type=cuid

INFO  Created: ./source/_posts/ck2c0zo1y0001gyyn5c2ma96m.md

It also works on hexo new2 too.

$ hexo new2 "Hello World!" --type=cuid

INFO  Created: ./source/_posts/ck2c0zo1y0001gyyn5c2ma96m.md

$ hexo new2 --type=cuid

INFO  Created: ./source/_posts/ck20kqmij0001ieyn4es62xh7.md

Define Custom Functions

Add a script file into the scripts folder of your hexo base directory. e.g. scripts/my_custom_path.js

Then register a generator function. The generator function should return a function that returns a string. e.g.

const { register } = require('hexo-unique-post-path');

register('my_custom_path', function(option) {
  let size = option.size || 8;
  let prefix = option.prefix || 'items-';
  return function(title) {
    return prefix + title.toLowerCase().replace(/[^\w]/g, '').substring(0, size);
  };
});
#_cofig.yml

+ unique_post_path:
+   type: my_custom_path
+   prefix: articles-
$ hexo new2 "Hello World!"
=> articles-hellowor.md

Related

  • id-generators - API for this module.
  • Awesome Unique ID - A curated list of awesome Unique ID libraries and resources.
  • transliteration - Universal Unicode to Latin transliteration + slugify module. Works on all platforms and with all major languages.
  • hexo-abbrlink - A Hexo plugin to generate static post link based on post titles.
  • hexo-permalink-pinyin - A Hexo plugin which convert Chinese title to transliterate permalink.

License

Copyright (c) 2019 dailyrandomphoto. Licensed under the MIT license.