-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c38583d
Showing
11 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": "hexo", | ||
"root": true, | ||
"globals": { | ||
"hexo": true | ||
}, | ||
"rules": { | ||
"one-var": 0, | ||
"operator-linebreak": [ | ||
2, | ||
"after" | ||
], | ||
"comma-spacing": [ | ||
2, | ||
{ | ||
"after": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
language: node_js | ||
|
||
sudo: false | ||
|
||
cache: | ||
apt: true | ||
directories: | ||
- node_modules | ||
|
||
node_js: | ||
- "8" | ||
- "10" | ||
- "node" | ||
|
||
script: | ||
- npm run eslint | ||
- npm run test-cov | ||
|
||
after_script: | ||
- npm install coveralls | ||
- nyc report --reporter=text-lcov | coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 dailyrandomphoto | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# hexo-unique-post-path | ||
|
||
[![NPM Version][npm-version-image]][npm-url] | ||
[![NPM Downloads][npm-downloads-image]][npm-url] | ||
[![LICENSE][license-image]][license-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![Coverage Status][coveralls-image]][coveralls-url] | ||
[![dependencies Status][dependencies-image]][dependencies-url] | ||
[![devDependencies Status][devDependencies-image]][devDependencies-url] | ||
|
||
This plug-in helps Hexo create new posts with unique auto-generated paths. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save hexo-unique-post-path | ||
``` | ||
|
||
## Usages | ||
|
||
There are two ways to use this plug-in to create new posts with unique auto-generated paths. | ||
|
||
### 1. Use `hexo new2` command | ||
```sh | ||
hexo new2 [layout] [title] | ||
``` | ||
|
||
e.g. | ||
```sh | ||
$ 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` via `unique_post_path` options in the `_config.yml` file. | ||
|
||
``` | ||
#_cofig.yml | ||
unique_post_path: | ||
title_default: "new post" | ||
``` | ||
|
||
### 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 | ||
``` | ||
## License | ||
Copyright (c) 2019 dailyrandomphoto. Licensed under the [MIT license][license-url]. | ||
|
||
[npm-url]: https://www.npmjs.com/package/hexo-unique-post-path | ||
[travis-url]: https://travis-ci.org/dailyrandomphoto/hexo-unique-post-path | ||
[coveralls-url]: https://coveralls.io/github/dailyrandomphoto/hexo-unique-post-path?branch=master | ||
[license-url]: LICENSE | ||
[dependencies-url]: https://david-dm.org/dailyrandomphoto/hexo-unique-post-path | ||
[devDependencies-url]: https://david-dm.org/dailyrandomphoto/hexo-unique-post-path?type=dev | ||
|
||
[npm-downloads-image]: https://img.shields.io/npm/dm/hexo-unique-post-path.svg | ||
[npm-version-image]: https://img.shields.io/npm/v/hexo-unique-post-path.svg | ||
[license-image]: https://img.shields.io/npm/l/hexo-unique-post-path.svg | ||
[travis-image]: https://img.shields.io/travis/dailyrandomphoto/hexo-unique-post-path/master | ||
[coveralls-image]: https://coveralls.io/repos/github/dailyrandomphoto/hexo-unique-post-path/badge.svg?branch=master | ||
[dependencies-image]: https://david-dm.org/dailyrandomphoto/hexo-unique-post-path/status.svg | ||
[devDependencies-image]: https://david-dm.org/dailyrandomphoto/hexo-unique-post-path/dev-status.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
(function(ctx) { | ||
const { config, extend } = ctx; | ||
const { console, filter } = extend; | ||
const myconfig = Object.assign({ | ||
auto: false, | ||
title_default: ' ' | ||
}, config.unique_post_path); | ||
|
||
console.register('new2', 'Create a new post with a auto generated unique path.', { | ||
usage: '[layout] [title]', | ||
arguments: [ | ||
{name: 'layout', desc: 'Post layout. Use post, page, draft or whatever you want.'}, | ||
{name: 'title', desc: 'Post title. Wrap it with quotations to escape.'} | ||
], | ||
options: [ | ||
{name: '-r, --replace', desc: 'Replace the current post if existed.'}, | ||
{name: '-s, --slug', desc: 'Post slug. Customize the URL of the post.'} | ||
] | ||
}, require('./new2')(myconfig)); | ||
|
||
if (myconfig.auto) { | ||
// register a filter with highest priority. | ||
filter.register('new_post_path', require('./unique_post_path_filter'), 1); | ||
} | ||
|
||
}(hexo)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const tildify = require('tildify'); // eslint-disable-line node/no-missing-require,node/no-extraneous-require | ||
const chalk = require('chalk'); // eslint-disable-line node/no-missing-require,node/no-extraneous-require | ||
const cuid = require('cuid'); | ||
|
||
const reservedKeys = { | ||
_: true, | ||
title: true, | ||
layout: true, | ||
slug: true, | ||
path: true, | ||
replace: true, | ||
// Global options | ||
config: true, | ||
debug: true, | ||
safe: true, | ||
silent: true | ||
}; | ||
|
||
module.exports = function(config) { | ||
|
||
return function newConsole(args) { | ||
// Display help message if user didn't input any arguments | ||
// if (!args._.length) { | ||
// return this.call('help', {_: ['new2']}); | ||
// } | ||
|
||
const data = { | ||
title: args._.pop() || config.title_default, | ||
layout: args._.length ? args._[0] : this.config.default_layout, | ||
slug: args.s || args.slug, | ||
path: cuid() | ||
}; | ||
|
||
const keys = Object.keys(args); | ||
|
||
for (let i = 0, len = keys.length; i < len; i++) { | ||
const key = keys[i]; | ||
if (!reservedKeys[key]) data[key] = args[key]; | ||
} | ||
|
||
return this.post.create(data, args.r || args.replace).then(post => { | ||
this.log.info('Created: %s', chalk.magenta(tildify(post.path))); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const cuid = require('cuid'); | ||
|
||
module.exports = function(data, replace) { | ||
// set path value as a value of cuid. | ||
data.path = cuid(); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "hexo-unique-post-path", | ||
"version": "0.0.1", | ||
"description": "This plug-in helps Hexo create new posts with unique auto-generated paths.", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"eslint": "eslint .", | ||
"test": "mocha test/index.js", | ||
"test-cov": "nyc npm run test" | ||
}, | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"cuid": "^2.1.6", | ||
"tildify": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-hexo": "^3.0.0", | ||
"mocha": "^6.2.1", | ||
"nyc": "^14.1.1" | ||
}, | ||
"keywords": [ | ||
"hexo", | ||
"blog", | ||
"cuid", | ||
"id", | ||
"generate", | ||
"plugin", | ||
"extension" | ||
], | ||
"files": [ | ||
"lib/", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"engines": { | ||
"node": ">=8.6.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dailyrandomphoto/hexo-unique-post-path.git" | ||
}, | ||
"author": "dailyrandomphoto <dailyrandomphoto@gmail.com> (https://www.dailyrandomphoto.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/dailyrandomphoto/hexo-unique-post-path/issues" | ||
}, | ||
"homepage": "https://github.com/dailyrandomphoto/hexo-unique-post-path#readme" | ||
} |
Empty file.