hexo-adsense 1.0.21 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +20 -6
  3. package/lib/index.js +8 -1
  4. package/lib/source/adblock.css +2 -83
  5. package/lib/source/adblock.js +1 -31
  6. package/lib/source/article-ads.css +2 -11
  7. package/lib/source/article-ads.js +1 -270
  8. package/lib/source/blogger-redirect.html +1 -14
  9. package/lib/source/https.js +1 -4
  10. package/lib/src/article-ads.d.ts +1 -1
  11. package/lib/src/article-ads.js +6 -6
  12. package/lib/src/config.d.ts +12 -19
  13. package/lib/src/config.js +3 -5
  14. package/lib/src/utils.d.ts +9 -1
  15. package/lib/src/utils.js +2 -2
  16. package/package.json +20 -5
  17. package/packages/hexo-cli-extras/.eslintrc +13 -0
  18. package/packages/hexo-cli-extras/LICENSE.md +20 -0
  19. package/packages/hexo-cli-extras/README.md +146 -0
  20. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  21. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  22. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  23. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  24. package/packages/hexo-cli-extras/index.js +48 -0
  25. package/packages/hexo-cli-extras/lib/edit.js +209 -0
  26. package/packages/hexo-cli-extras/lib/env.js +52 -0
  27. package/packages/hexo-cli-extras/lib/extensions.js +23 -0
  28. package/packages/hexo-cli-extras/lib/integrate.js +87 -0
  29. package/packages/hexo-cli-extras/lib/isolate.js +179 -0
  30. package/packages/hexo-cli-extras/lib/remove.js +145 -0
  31. package/packages/hexo-cli-extras/lib/rename.js +171 -0
  32. package/packages/hexo-cli-extras/package.json +34 -0
  33. package/packages/hexo-extend-injector2/.eslintrc +4 -0
  34. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +27 -0
  35. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +24 -0
  36. package/packages/hexo-extend-injector2/.vscode/settings.json +10 -0
  37. package/packages/hexo-extend-injector2/LICENSE +165 -0
  38. package/packages/hexo-extend-injector2/README-ZH.md +189 -0
  39. package/packages/hexo-extend-injector2/README.md +191 -0
  40. package/packages/hexo-extend-injector2/USAGE.md +38 -0
  41. package/packages/hexo-extend-injector2/index.js +13 -0
  42. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +79 -0
  43. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +13 -0
  44. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +29 -0
  45. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +42 -0
  46. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +10 -0
  47. package/packages/hexo-extend-injector2/lib/default-config.js +52 -0
  48. package/packages/hexo-extend-injector2/lib/filter.js +24 -0
  49. package/packages/hexo-extend-injector2/lib/helper/injector.js +6 -0
  50. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +14 -0
  51. package/packages/hexo-extend-injector2/lib/injector.js +128 -0
  52. package/packages/hexo-extend-injector2/lib/load.js +45 -0
  53. package/packages/hexo-extend-injector2/lib/next-point.js +19 -0
  54. package/packages/hexo-extend-injector2/lib/next.js +87 -0
  55. package/packages/hexo-extend-injector2/lib/order.js +9 -0
  56. package/packages/hexo-extend-injector2/package.json +49 -0
  57. package/packages/hexo-extend-injector2/renovate.json +6 -0
  58. package/packages/hexo-extend-injector2/test/.eslintrc +3 -0
  59. package/packages/hexo-extend-injector2/test/index.js +18 -0
  60. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +86 -0
  61. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +36 -0
  62. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +3 -0
  63. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +5 -0
  64. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +45 -0
  65. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +69 -0
  66. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +250 -0
  67. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +37 -0
  68. package/packages/hexo-extend-injector2/test/lib/injector.js +93 -0
  69. package/packages/memoize/CHANGELOG.md +82 -0
  70. package/packages/memoize/CHANGES +124 -0
  71. package/packages/memoize/LICENSE +15 -0
  72. package/packages/memoize/README.md +503 -0
  73. package/packages/memoize/ext/async.js +154 -0
  74. package/packages/memoize/ext/dispose.js +33 -0
  75. package/packages/memoize/ext/max-age.js +90 -0
  76. package/packages/memoize/ext/max.js +27 -0
  77. package/packages/memoize/ext/promise.js +147 -0
  78. package/packages/memoize/ext/ref-counter.js +48 -0
  79. package/packages/memoize/index.js +34 -0
  80. package/packages/memoize/lib/configure-map.js +182 -0
  81. package/packages/memoize/lib/methods.js +32 -0
  82. package/packages/memoize/lib/registered-extensions.js +1 -0
  83. package/packages/memoize/lib/resolve-length.js +15 -0
  84. package/packages/memoize/lib/resolve-normalize.js +17 -0
  85. package/packages/memoize/lib/resolve-resolve.js +21 -0
  86. package/packages/memoize/lib/weak.js +134 -0
  87. package/packages/memoize/methods-plain.js +3 -0
  88. package/packages/memoize/methods.js +3 -0
  89. package/packages/memoize/normalizers/get-1.js +29 -0
  90. package/packages/memoize/normalizers/get-fixed.js +71 -0
  91. package/packages/memoize/normalizers/get-primitive-fixed.js +16 -0
  92. package/packages/memoize/normalizers/get.js +90 -0
  93. package/packages/memoize/normalizers/primitive.js +9 -0
  94. package/packages/memoize/package.json +60 -0
  95. package/packages/memoize/plain.js +37 -0
  96. package/packages/memoize/profile.js +107 -0
  97. package/packages/memoize/repository.md +1 -0
  98. package/packages/memoize/weak-plain.js +3 -0
  99. package/packages/memoize/weak.js +3 -0
@@ -0,0 +1,146 @@
1
+ # hexo-cli-extras
2
+
3
+ This is a simple plugin for [Hexo](https://github.com/hexojs/hexo), a Node.js-based static site generator/blog framework.
4
+
5
+ The plugin adds a handful of useful commands to the Hexo command-line interface: `edit`, `rename`, `remove`, `isolate` and `integrate`.
6
+
7
+ Basic terminal editing:
8
+
9
+ ![example](./docs/basic.gif)
10
+
11
+ Basic GUI editing and selection on tag (sorry for the bad resolution):
12
+
13
+ ![example](./docs/gui.gif)
14
+
15
+ A more detailed explanation of the commands and their options is included below, but remember that you can run `hexo help` followed by any command in your terminal to get an overview (eg `hexo help edit`). You may also find the tips and notes at the very bottom of this README useful.
16
+
17
+ ## Installation
18
+
19
+ ```
20
+ npm install --save hexo-cli-extras
21
+ ```
22
+
23
+ Note that the plugin *must* be installed locally. So if you have multiple blogs, you have to install it separately for each of them.
24
+
25
+ ## edit command
26
+
27
+ Select a post, page or draft using search terms and/or filters and open it in your favorite terminal $EDITOR or associated GUI text editor. If multiple items match your query, a menu will be displayed. By the way, if you're a vim-user with a distaste for arrow-keys, the menu supports vim-style keybindings (yay).
28
+
29
+ ```
30
+ hexo edit [title] [-a | --after MM-DD-YYYY] [-b | --before MM-DD-YYYY] [-c | --category | --categories CATEGORY] [-f | --folder SUBFOLDER] [-l | --layout] [-t | --tag | --tags TAG] [--draft | --drafts] [-g | --gui] [-p | --page | --pages]
31
+ ```
32
+
33
+ ### quick examples
34
+
35
+ ```
36
+ hexo edit
37
+ ```
38
+ --> gives you a menu with *all* your posts in descending chronological order, select one to edit using the arrow keys or `j`/`k`
39
+
40
+ ```
41
+ hexo edit search term
42
+ ```
43
+ --> uses the regular expressions `search` and `term` to filter the titles (or slugs) of your articles and displays a menu with all matches -- if only one article matches, it will open automatically in your editor
44
+
45
+ ```
46
+ hexo edit -a 11-11-2015 -g
47
+ ```
48
+ --> gives you a menu with all posts published after 11/11/2015 -- the selected article will open in gui mode
49
+
50
+ ```
51
+ hexo edit neovim -c vim
52
+ ```
53
+ --> looks in the database for articles in the "vim" category which match the regular expression "neovim" in their titles or slugs
54
+
55
+ ### detailed information (get this info on the command line with `hexo help edit`)
56
+
57
+ - `title` is a regular expression (case insensitive and spaces are allowed) for matching the title of a post
58
+ - `-a` or `--after` (optional) filters out all posts that were made before the given date. A little parsing is done to help you, but use `MM-DD-YYYY` for best results
59
+ - `-b` or `--before` (optional) filters out all posts that were made after the given date. A little parsing is done to help you, but use `MM-DD-YYYY` for best results
60
+ - `-c` or `--category` (optional) filters posts on category
61
+ - `-f` or `--folder` (optional) is (part of) the name of a subfolder in `hexo_dir/source` to narrow down your search in case you have multiple folders (for filtering on drafts, prefer to use `-d`)
62
+ - `-l` or `--layout` (optional) filters posts/pages with a specific layout
63
+ - `-t` or `--tag` (optional) filters posts on tag
64
+ - `--draft` or `--drafts` (optional) excludes all published posts
65
+ - `-g` or `--gui` (optional) causes selected files to open using an associated GUI editor, rather than a terminal editor set in the $EDITOR environment variable
66
+ - `-p` or `--page` (optional) selects pages instead of posts
67
+
68
+
69
+ *Note*: boolean options can be combined (for example `hexo edit -dp` to search for drafts that are pages)
70
+
71
+ *Note*: Drafts only appear in searches without the `--drafts` option if you have `render_drafts` set to true in `_config.yml`. If set to false, you must use the `--draft` option to filter on drafts. Also, drafts are excluded automatically when you use any of the date filters, because dates make little sense with drafts.
72
+
73
+ *Note*: Filter on title first and use boolean options last or you may get unexpected results. For example, `hexo edit -g my post` will filter just on "post" whereas `hexo edit my draft -g` will correctly filter on "my draft".
74
+
75
+ *Note*: By default, files open in your current terminal window using your `$EDITOR` environment variable. Set it in your dotfiles (for example, in `.bashrc` or `.zshrc`).
76
+
77
+ *Note*: The `gui` option (or the lack of an `$EDITOR` variable) will cause files to open with `xdg-open` (linux, osx) or `start` (windows). If you're on linux and nothing seems to happen, you can change the handler for plain text markdown files to a `*.desktop` file of your choice. For example, for Sublime Text: `xdg-mime default sublime-text.desktop text/plain`
78
+
79
+ ## rename command
80
+
81
+ Rename a post, page or draft. The title and the filename can be renamed independently or both at the same time.
82
+
83
+ ![example](./docs/rename.png)
84
+
85
+ ```
86
+ hexo rename <old title/slug> <-n | --new "new title">
87
+ ```
88
+
89
+ `old title/slug` is one or more regular expressions to find a post or page. If more match your regex, a selection menu will be displayed.
90
+
91
+ `new title` is the new title for your post. In case you just want to rename the file, it will be `slugize`d automatically (ie it will get converted to lower case, and all special characters and spaces will be made url-friendly).
92
+
93
+ After selecting a file, you will be presented with another menu. From there you can choose whether to rename the filename, the title of the post, both, or cancel altogether.
94
+
95
+ *Note*: if you have set `render_drafts` to false in `_config.yml`, you won't be able to rename drafts from the command line. It works only with that setting set to true or if you publish the post first.
96
+
97
+ *Note*: wrap the new title in single or double quotes! If you forget, the presence of spaces or special characters may cause strange behavior.
98
+
99
+
100
+ ## remove command
101
+
102
+ Delete a post.
103
+
104
+ ![example](./docs/remove.png)
105
+
106
+ ```
107
+ hexo remove <search terms>
108
+ ```
109
+
110
+ Search for a post and delete it after confirmation. This will cause the irreversible removal of the selected post *and* its associated asset folder (if it exists), along with all its contents.
111
+
112
+ ## isolate command
113
+
114
+ Isolate a post by temporarily removing all others from the build process.
115
+
116
+ ```
117
+ hexo isolate <search terms> [-a | --all]
118
+ ```
119
+
120
+ This command was inspired by Octopress. For testing purposes, you may want to isolate a post so you can work on it and test it in isolation from all others. This accomplishes that aim by moving all posts and asset directories (pages are not supported right now) to an `_exile` subfolder, where they will be ignored.
121
+
122
+ The `-a` or `--all` option will cause *all* posts to be moved, and your search terms to be ignored.
123
+
124
+ Run `hexo integrate` to restore the posts to their previous location.
125
+
126
+ ## integrate command
127
+
128
+ Restores all exiled posts.
129
+
130
+ ```
131
+ hexo integrate
132
+ ```
133
+
134
+ ## Info
135
+
136
+ - It doesn't matter where in the hexo directory you are on the command line. As long as you are inside a hexo directory somewhere, the commands should work.
137
+
138
+ - Installing this plugin will also cause any new post you create with `hexo new ...` to open automatically in your text editor.
139
+
140
+ - The terminal menu may not work as expected in the default Windows command shell (`cmd.exe`), but it should work just fine in more powerful shells.
141
+
142
+ - If you don't like the command-line centric workflow this plugin encourages, you may want to consider using an administration plugin instead - check out [hexo-admin](https://github.com/jaredly/hexo-admin) or [hexo-hey](https://github.com/nihgwu/hexo-hey).
143
+
144
+ - Filter on title first and use boolean options last or you may get unexpected results. For example, `hexo edit -g my post` will filter just on "post" whereas `hexo edit my draft -g` will correctly filter on "my draft".
145
+
146
+ - By default, files open in your current terminal window using your `EDITOR` environment variable. Set it somewhere in your dotfiles (`.bashrc` or `.zshrc` are good locations, and don't forget to source the file or reboot before testing). If `$EDITOR` doesn't exist, or if you use the `gui` option, files will open with [xdg-open](https://wiki.archlinux.org/index.php/default_applications#xdg-open_2) (linux, osx) or `start` (windows) instead.
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ require('./lib/extensions')(hexo);
4
+
5
+ hexo.extend.console.register('edit', 'Edit a post or draft with your favorite $EDITOR', {
6
+ desc: 'Edit a post or draft with your favorite $EDITOR. Filter on title (if applicable), before using optional arguments.',
7
+ usage: '[title] [-a | --after MM-DD-YYYY] [-b | --before MM-DD-YYYY] [-c | --category CATEGORY] [-d | --draft | --drafts] [-f | --folder FOLDER] [-g | --gui] [-l | --layout LAYOUT] [-p | --page | --pages] [-t | --tag | --tags TAG]',
8
+ arguments: [
9
+ {name: 'title', desc: '(Part of) the title of a post. If more posts match this regex, a menu will be called.'},
10
+ ],
11
+ options: [
12
+ {name: '-a, --after', desc: 'Only consider posts after this date (MM-DD-YYYY)'},
13
+ {name: '-b, --before', desc: 'Only consider posts before this date (MM-DD-YYYY)'},
14
+ {name: '-c, --category, --categories', desc: 'Category to filter on.'},
15
+ {name: '-d, --draft, --drafts', desc: 'Only consider drafts'},
16
+ {name: '-f, --folder', desc: 'Name of subfolder to filter on.'},
17
+ {name: '-g, --gui', desc: 'Open file with associated GUI text editor. Default is to open in terminal using $EDITOR. If no $EDITOR is found, it will fall back to gui mode.'},
18
+ {name: '-l, --layout', desc: 'Only consider posts with a given layout'},
19
+ {name: '-p, --page, --pages', desc: 'Only consider pages'},
20
+ {name: '-t, --tag, --tags', desc: 'Tag to filter on.'},
21
+ ],
22
+ }, require('./lib/edit'));
23
+
24
+ hexo.extend.console.register('rename', 'Rename a post or draft', {
25
+ desc: 'Rename a post or draft. Search for a post and set a new name with the -n or --new option, followed by the new title wrapped in single or double quotes',
26
+ usage: '<old name> <-n | --new new name>',
27
+ options: [
28
+ {name: '-n, --new', desc: '(required) The new title. Wrap in single or double quotes if the title includes spaces.'},
29
+ ],
30
+ }, require('./lib/rename'));
31
+
32
+ hexo.extend.console.register('remove', 'Remove a post or draft', {
33
+ desc: 'Search for a post or draft and remove it.',
34
+ usage: '<search terms for a post to be deleted>',
35
+ }, require('./lib/remove'));
36
+
37
+ hexo.extend.console.register('isolate', 'Isolate a post or page by temporarily removing all others from the build process', {
38
+ desc: 'Move all posts to an ignored _exile subfolder, except for the one matching a given search term. If multiple posts match, a menu will be called. This can be useful for speeding up testing, but don\'t forget to use the integrate command to restore the exiled posts back to their previous location before deploying your site.',
39
+ usage: '[search term]',
40
+ options: [
41
+ {name: '-a, --all', desc: 'Stash all posts in _exile, including the one for which the pattern matches.'},
42
+ ],
43
+ }, require('./lib/isolate'));
44
+
45
+ hexo.extend.console.register('integrate', 'Restore isolated posts', {
46
+ desc: 'Restore all exiled posts from _posts/_exile back to _posts. Opposite of the isolate command.',
47
+ usage: '',
48
+ }, require('./lib/integrate'));
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+ var moment = require('moment');
5
+ var open = require('opn');
6
+ var editor = process.env.EDITOR;
7
+ var spawn = require('child_process').spawn;
8
+ var path = require('path');
9
+ var inquirer = require('inquirer');
10
+ var Promise = require('bluebird');
11
+
12
+ module.exports = function modExports(args) {
13
+ var filters = {
14
+ title: args._ || '',
15
+
16
+ after: args.a || args.after || null,
17
+ before: args.b || args.before || null,
18
+ cat: args.c || args.category || args.categories || null,
19
+ draft: args.draft || args.drafts || null,
20
+ folder: args.f || args.folder || null,
21
+ layout: args.l || args.layout || null,
22
+ tag: args.t || args.tag || null,
23
+ };
24
+
25
+ var gui = args.g || args.gui || !editor;
26
+ var page = args.p || args.page || args.pages || null;
27
+
28
+ // load in the posts before processing them
29
+ this.load().then(function loadDB() {
30
+ var sourceDir = this.source_dir;
31
+ var searchDir = sourceDir;
32
+
33
+ var query = (page) ? 'pages' : 'posts';
34
+
35
+ // the following promise chain details the main functionality
36
+ loadArticles(query, this.locals).then(function filter(articles) {
37
+ return filterArticles(articles, filters);
38
+ }).then(function select(filtered) {
39
+ return selectArticle(filtered);
40
+ }).then(function openFn(selected) {
41
+ openFile(selected);
42
+ }).catch(function catchAll(err) {
43
+ console.log(err.stack ? chalk.red(err.stack) : chalk.red('Error: ') + chalk.gray(err));
44
+ });
45
+
46
+ function loadArticles(dataType, locals) {
47
+ return Promise.resolve(locals.get(dataType).sort('-date').toArray());
48
+ }
49
+
50
+ function filterArticles(items, filterObj) {
51
+ var results;
52
+ // allow omission of leading underscore or trailing s for the common _drafts and _posts folders;
53
+ if (/post|draft/.test(filterObj.folder)) {
54
+ filterObj.folder = (/^_/.test(filterObj.folder)) ? filterObj.folder : '_' + filterObj.folder;
55
+ filterObj.folder = (/s$/.test(filterObj.folder)) ? filterObj.folder : filterObj.folder + 's';
56
+ }
57
+
58
+ results = filterTitle(items, filterObj.title);
59
+
60
+ results = (filterObj.draft) ? filterDrafts(results) : results;
61
+ results = (filterObj.layout) ? filterLayout(results, filterObj.layout) : results;
62
+ results = (filterObj.folder) ? filterFolder(results, filterObj.folder) : results;
63
+ results = (filterObj.tag) ? filterTag(results, filterObj.tag) : results;
64
+ results = (filterObj.cat) ? filterCategory(results, filterObj.cat) : results;
65
+ results = (filterObj.before) ? filterBefore(results, filterObj.before) : results;
66
+ results = (filterObj.after) ? filterAfter(results, filterObj.after) : results;
67
+
68
+ return results;
69
+
70
+ // filter the posts with the supplied regular expression
71
+ function filterTitle(posts, title) {
72
+ var reTitle = title.map(function makeRE(word) {
73
+ return new RegExp(word, 'i');
74
+ });
75
+
76
+ return posts.filter(function filterPosts(post) {
77
+ return reTitle.every(function checkRE(regex) {
78
+ return regex.test(post.title) || regex.test(post.slug);
79
+ });
80
+ });
81
+ }
82
+
83
+ // filter the posts using a subfolder if supplied
84
+ function filterFolder(posts, folder) {
85
+ var reFolder = new RegExp(folder);
86
+ return posts.filter(function filterPosts(post) {
87
+ return reFolder.test(post.source.substr(0, post.source.lastIndexOf(path.sep)));
88
+ });
89
+ }
90
+
91
+ // filter the posts using a tag if supplied
92
+ function filterTag(posts, tag) {
93
+ var reTag = new RegExp(tag);
94
+ return posts.filter(function filterPosts(post) {
95
+ return post.tags.data.some(function checkRe(postTag) {
96
+ return reTag.test(postTag.name);
97
+ });
98
+ });
99
+ }
100
+
101
+ // filter the posts using a category if supplied
102
+ function filterCategory(posts, cat) {
103
+ var reCat = new RegExp(cat);
104
+ return posts.filter(function filterPosts(post) {
105
+ return post.categories.data.some(function checkRe(postCat) {
106
+ return reCat.test(postCat.name);
107
+ });
108
+ });
109
+ }
110
+
111
+ // filter the posts using a layout if supplied
112
+ function filterLayout(posts, layout) {
113
+ var reLayout = new RegExp(layout, 'i');
114
+
115
+ return posts.filter(function filterPosts(post) {
116
+ return reLayout.test(post.layout);
117
+ });
118
+ }
119
+
120
+ // filter out all non-published posts
121
+ function filterDrafts(posts) {
122
+ return posts.filter(function filterPosts(post) {
123
+ return !post.published;
124
+ });
125
+ }
126
+
127
+ // filter the posts using a before date if supplied
128
+ function filterBefore(posts, before) {
129
+ var momentBefore = moment(before.replace(/\//g, '-'), 'MM-DD-YYYY', true);
130
+ if (!momentBefore.isValid()) {
131
+ console.log(chalk.red('Before date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
132
+ return posts;
133
+ }
134
+
135
+ return posts.filter(function filterPosts(post) {
136
+ return moment(post.date).isBefore(momentBefore);
137
+ });
138
+ }
139
+
140
+ // filter the posts using an after date if supplied
141
+ function filterAfter(posts, after) {
142
+ var momentAfter = moment(after.replace(/\//g, '-'), 'MM-DD-YYYY', true);
143
+ if (!momentAfter.isValid()) {
144
+ console.log(chalk.red('After date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
145
+ return posts;
146
+ }
147
+
148
+ return posts.filter(function filterPosts(post) {
149
+ return moment(post.date).isAfter(momentAfter);
150
+ });
151
+ }
152
+ }
153
+
154
+ function selectArticle(items) {
155
+ if (items.length === 0) {
156
+ return Promise.reject('Sorry, no articles match your query.');
157
+ }
158
+
159
+ if (items.length === 1) {
160
+ // no menu necessary if there is only one matching file
161
+ var selected = path.join(searchDir, items[0].source);
162
+ return Promise.resolve(selected);
163
+ }
164
+
165
+ // populate a list of entries to use for the menu -- slugs are easy because they show the subfolder and can easily
166
+ // be put back together with the searchDir to open the file
167
+ var entries = items.map(function makeEntries(post) {
168
+ var entry = '';
169
+ var loc = post.source.substr(0, post.source.lastIndexOf(path.sep));
170
+ if (!post.published) {
171
+ entry = ['[', chalk.yellow.bgBlack('draft'), '] ', post.title].join('');
172
+ } else {
173
+ entry = ['[', chalk.gray(post.date.format('MM-DD-YYYY')), '] ', post.title, ' (', chalk.green(loc), ')'].join('');
174
+ }
175
+
176
+ return entry;
177
+ });
178
+
179
+ // display the menu
180
+ return inquirer.prompt([
181
+ {
182
+ type: 'list',
183
+ name: 'file',
184
+ message: 'Select the file you wish to edit.',
185
+ choices: entries,
186
+ }
187
+ ]).then(function getAnswer(answer) {
188
+ var pos = entries.indexOf(answer.file);
189
+ var selected = path.join(sourceDir, items[pos].source);
190
+
191
+ if (!selected) {
192
+ return Promise.reject('Invalid choice.');
193
+ }
194
+ return selected;
195
+ });
196
+ }
197
+
198
+ // spawn process and open with associated gui or terminal editor
199
+ function openFile(file) {
200
+ var edit;
201
+ if (!editor || gui) {
202
+ open(file);
203
+ } else {
204
+ edit = spawn(editor, [file], {stdio: 'inherit'});
205
+ edit.on('exit', process.exit);
206
+ }
207
+ }
208
+ }.bind(this));
209
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ const Hexo = require("hexo");
3
+ const { memoize } = require("underscore");
4
+ const argv = require("minimist")(process.argv.slice(2));
5
+
6
+ /**
7
+ * Check is production or development
8
+ * @param {Hexo} inHexo
9
+ * @returns
10
+ */
11
+ const getEnv = memoize(function (inHexo) {
12
+ var DEV = "development";
13
+ var PRD = "production";
14
+ // --development
15
+ const arg = typeof argv["development"] == "boolean" && argv["development"];
16
+
17
+ // set NODE_ENV = "development"
18
+ const env = process.env.NODE_ENV && process.env.NODE_ENV.toString().toLowerCase() === "development";
19
+
20
+ // define is development
21
+ const isDev = arg || env;
22
+
23
+ if (inHexo) {
24
+ if (isDev) return DEV;
25
+ if (typeof inHexo.env.args.development == "boolean" && inHexo.env.args.development) return DEV;
26
+ if (inHexo.env.args._ && inHexo.env.args._.length > 0) {
27
+ for (var i = 0; i < inHexo.env.args._.length; i++) {
28
+ if (inHexo.env.args._[i] == "s" || inHexo.env.args._[i] == "server") return DEV;
29
+ if (inHexo.env.args._[i] == "d" || inHexo.env.args._[i] == "deploy") return PRD;
30
+ if (inHexo.env.args._[i] == "g" || inHexo.env.args._[i] == "generate") return PRD;
31
+ }
32
+ }
33
+ }
34
+
35
+ return null;
36
+ });
37
+
38
+ const isDev = memoize(function (hexo) {
39
+ return getEnv(hexo) == "development";
40
+ });
41
+
42
+ const isProd = memoize(function (hexo) {
43
+ return getEnv(hexo) == "production";
44
+ });
45
+
46
+ module.exports = {
47
+ env: function (inHexo) {
48
+ return getEnv(inHexo);
49
+ },
50
+ isProd,
51
+ isDev,
52
+ };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ module.exports = function modExports(hexo) {
4
+ var open = require('opn');
5
+ var editor = process.env.EDITOR;
6
+ var spawn = require('child_process').spawn;
7
+
8
+ // extend `hexo new` to open newly created post/draft
9
+ hexo.on('new', function onNew(post) {
10
+ var edit;
11
+ var content = post.content;
12
+
13
+ // only open a new empty post -- prevent opening on publishing an already written one
14
+ if (content.substr(content.indexOf('\n---\n')).length === 5) {
15
+ if (!editor) {
16
+ open(post.path);
17
+ } else {
18
+ edit = spawn(editor, [post.path], {stdio: 'inherit'});
19
+ edit.on('exit', process.exit);
20
+ }
21
+ }
22
+ });
23
+ };
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var Promise = require('bluebird');
4
+ var chalk = require('chalk');
5
+ var fsStat = Promise.promisify(require('fs').stat);
6
+ var fsRename = Promise.promisify(require('fs').rename);
7
+ var fsReaddir = Promise.promisify(require('fs').readdir);
8
+ var path = require('path');
9
+
10
+ module.exports = function modExports() {
11
+
12
+ // load DB (kind of unnecessary here, but it does give easy access to source_dir)
13
+ this.load().then(function loadDB() {
14
+ var postsDir = path.join(this.source_dir, '_posts');
15
+ var exileDir = path.join(postsDir, '_exile');
16
+
17
+ isExileDir(exileDir).then(function checkExileDir(exists) {
18
+ if (!exists) {
19
+ process.exit();
20
+ }
21
+ }).then(function lsDir() {
22
+ return getExiledPosts(exileDir);
23
+ }).then(function checkExiledPosts(files) {
24
+ if (!files) {
25
+ console.log(chalk.red('No exiled posts detected. Exiting..'));
26
+ process.exit();
27
+ } else {
28
+ return files;
29
+ }
30
+ }).then(function processFiles(files) {
31
+ // set the exiled files up for restoration
32
+ return files.map(function mapAbsolutePaths(file) {
33
+ return {
34
+ origin: path.join(exileDir, file),
35
+ destination: path.join(postsDir, file),
36
+ };
37
+ });
38
+ }).then(function doIntegrate(files) {
39
+ var movePromises = files.map(function makePromise(file) {
40
+ return new Promise(function returnPromise(resolve) {
41
+ resolve(move(file.origin, file.destination));
42
+ });
43
+ });
44
+
45
+ Promise.all(movePromises).then(function allDone() {
46
+ console.log(chalk.gray('All exiled posts and asset directories restored.'));
47
+ });
48
+ }).catch(function catchUncaught(err) {
49
+ console.log(err.stack ? chalk.red(err.stack) : chalk.red('Error: ') + chalk.gray(err));
50
+ });
51
+
52
+ function move(origin, destination) {
53
+ return fsRename(origin, destination).then(function doMove() {
54
+ // console.log('%s moved to %s', origin, destination);
55
+ }).catch(function catchMove(err) {
56
+ console.log('%s could not be moved to %s: %s', origin, destination, err);
57
+ });
58
+ }
59
+
60
+ function isExileDir(dir) {
61
+ return fsStat(dir).then(function doCheckDir(stats) {
62
+ if (stats.isFile()) {
63
+ console.log(chalk.gray(dir), 'seems to be a file on your filesystem! It needs to be either non-existent or a directory, so please rename your _exile post and run', chalk.yellow('hexo isolate'), 'before using this command.');
64
+ return false;
65
+ } else if (stats.isDirectory()) {
66
+ return true;
67
+ } else {
68
+ console.log(chalk.gray(dir), 'seems to be neither a file nor a directory! This really shouldn\'t be happening, please issue a bug report.');
69
+ return false;
70
+ }
71
+ }).catch(function catchCheckDir() {
72
+ // The directory doesn't exist
73
+ console.log(chalk.red('No _exile dir detected. Have you run'), chalk.yellow('hexo isolate'), chalk.red('first?'));
74
+ return false;
75
+ });
76
+ }
77
+
78
+ function getExiledPosts(dir) {
79
+ return fsReaddir(dir).then(function doReadDir(contents) {
80
+ return contents;
81
+ }).catch(function catchCheckDir(err) {
82
+ console.log(chalk.red('Error: '), err);
83
+ });
84
+ }
85
+ }.bind(this));
86
+ };
87
+