eleventy-generate-posts 0.0.5 → 0.0.7
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.
- package/changelog.md +10 -0
- package/eleventy-generate-posts.js +25 -6
- package/package.json +2 -2
- package/readme.md +14 -11
package/changelog.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 20260320 (v0.0.7)
|
|
4
|
+
|
|
5
|
+
* Added support for timestamps (something I use in my sites instead of a simple article date).
|
|
6
|
+
* Pressing escape or ctrl-C during prompting now fails gracefully.
|
|
7
|
+
* Show post count in output.
|
|
8
|
+
|
|
9
|
+
## 20260318 (v0.0.6)
|
|
10
|
+
|
|
11
|
+
Replaced the word generator API with a different one (https://random-word-api.herokuapp.com/home) since the original was no longer available.
|
|
12
|
+
|
|
3
13
|
## 20240109 (v0.0.5)
|
|
4
14
|
|
|
5
15
|
Added `-g` parameter used to append generator content to the end of generated posts:
|
|
@@ -22,11 +22,18 @@ const spaces40 = '-'.repeat(40);
|
|
|
22
22
|
const red = HighlightType.Red;
|
|
23
23
|
const yellow = HighlightType.Yellow;
|
|
24
24
|
const green = HighlightType.Green;
|
|
25
|
+
var counterLen;
|
|
26
|
+
var counterStr;
|
|
25
27
|
var numPosts;
|
|
26
28
|
var startYear;
|
|
27
29
|
var tag;
|
|
28
30
|
var targetFolder;
|
|
31
|
+
var timestampMode;
|
|
29
32
|
var yearMode;
|
|
33
|
+
const onCancelPrompt = () => {
|
|
34
|
+
log.info('\nOperation cancelled by user!');
|
|
35
|
+
process.exit(0);
|
|
36
|
+
};
|
|
30
37
|
function zeroPad(tmpVal, numChars = 2) {
|
|
31
38
|
return tmpVal.toString().padStart(numChars, '0');
|
|
32
39
|
}
|
|
@@ -78,14 +85,14 @@ if (debugMode) {
|
|
|
78
85
|
log.level(debugMode ? log.DEBUG : log.INFO);
|
|
79
86
|
const generatorInfo = process.argv.includes('-g');
|
|
80
87
|
if (generatorInfo) {
|
|
81
|
-
writeConsole(green, '
|
|
88
|
+
writeConsole(green, 'Append generator info', 'enabled\n');
|
|
82
89
|
}
|
|
83
90
|
const questions = [
|
|
84
91
|
{
|
|
85
92
|
type: 'number',
|
|
86
93
|
name: 'numPosts',
|
|
87
94
|
initial: 10,
|
|
88
|
-
message: 'Number of posts to generate?'
|
|
95
|
+
message: 'Number of posts to generate (1-100)?'
|
|
89
96
|
}, {
|
|
90
97
|
type: 'text',
|
|
91
98
|
name: 'targetFolder',
|
|
@@ -106,14 +113,21 @@ const questions = [
|
|
|
106
113
|
name: 'yearMode',
|
|
107
114
|
initial: true,
|
|
108
115
|
message: 'Use year folder for posts?'
|
|
109
|
-
},
|
|
116
|
+
}, {
|
|
117
|
+
type: 'confirm',
|
|
118
|
+
name: 'timestampMode',
|
|
119
|
+
initial: true,
|
|
120
|
+
message: 'Include timestamp in post metadata?'
|
|
121
|
+
}
|
|
110
122
|
];
|
|
111
|
-
const response = await prompts(questions);
|
|
123
|
+
const response = await prompts(questions, { onCancel: onCancelPrompt });
|
|
112
124
|
targetFolder = response.targetFolder;
|
|
113
125
|
numPosts = response.numPosts;
|
|
126
|
+
counterLen = numPosts.toString().length;
|
|
114
127
|
startYear = response.startYear;
|
|
115
128
|
tag = response.tag;
|
|
116
129
|
yearMode = response.yearMode;
|
|
130
|
+
timestampMode = response.timestampMode;
|
|
117
131
|
console.log('\nSettings Summary:');
|
|
118
132
|
console.log(spaces40);
|
|
119
133
|
writeConsole(yellow, 'Number of posts', numPosts.toString());
|
|
@@ -121,6 +135,7 @@ writeConsole(yellow, 'Target Folder', targetFolder);
|
|
|
121
135
|
writeConsole(yellow, 'Start Year', startYear.toString());
|
|
122
136
|
writeConsole(yellow, 'Tag', tag);
|
|
123
137
|
writeConsole(yellow, 'Year mode', yearMode ? 'enabled' : 'disabled');
|
|
138
|
+
writeConsole(yellow, 'Timestamp mode', timestampMode ? 'enabled' : 'disabled');
|
|
124
139
|
if (!(numPosts > 0 && numPosts < 101)) {
|
|
125
140
|
writeConsole(red, 'Error', 'Number of posts must be between 1 and 100');
|
|
126
141
|
process.exit(1);
|
|
@@ -140,7 +155,7 @@ numPosts++;
|
|
|
140
155
|
for (let i = 1; i < numPosts; i++) {
|
|
141
156
|
log.debug('\nGetting random words (this may take a few seconds)');
|
|
142
157
|
let wordCount = getRandomInt(4) + 3;
|
|
143
|
-
let letTitleRes = await fetch(`https://random-word-api.
|
|
158
|
+
let letTitleRes = await fetch(`https://random-word-api.herokuapp.com/word?number=${wordCount}`);
|
|
144
159
|
let titleWords = await letTitleRes.json();
|
|
145
160
|
titleWords = titleWords.map((a) => a.charAt(0).toUpperCase() + a.substr(1));
|
|
146
161
|
let postTitle = titleWords.join(' ');
|
|
@@ -153,6 +168,9 @@ for (let i = 1; i < numPosts; i++) {
|
|
|
153
168
|
date: postDate,
|
|
154
169
|
tags: tag
|
|
155
170
|
};
|
|
171
|
+
if (timestampMode) {
|
|
172
|
+
postFm.timestamp = currentDate.toISOString();
|
|
173
|
+
}
|
|
156
174
|
log.debug('Getting bacon ipsum text (this may take a few seconds)...');
|
|
157
175
|
let response = await fetch(`https://baconipsum.com/api/?type=all-meat¶s=${getRandomInt(10)}&start-with-lorem=1`);
|
|
158
176
|
let postContent = await response.json();
|
|
@@ -170,6 +188,7 @@ for (let i = 1; i < numPosts; i++) {
|
|
|
170
188
|
fs.mkdirSync(outputFilePath, { recursive: true });
|
|
171
189
|
}
|
|
172
190
|
var outputFilePath = path.join(outputFilePath, postTitle.toLowerCase().replaceAll(' ', '-') + '.md');
|
|
173
|
-
|
|
191
|
+
counterStr = i.toString().padStart(counterLen);
|
|
192
|
+
writeConsole(green, `[${counterStr}] Writing`, outputFilePath);
|
|
174
193
|
fs.writeFileSync(outputFilePath, thePost, 'utf8');
|
|
175
194
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-generate-posts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Generates batches of Eleventy posts",
|
|
5
5
|
"author": "John M. Wargo",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/johnwargo/eleventy-generate-posts"
|
|
9
|
+
"url": "git+https://github.com/johnwargo/eleventy-generate-posts.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "eleventy-generate-posts.js",
|
package/readme.md
CHANGED
|
@@ -43,6 +43,7 @@ by John M. Wargo (https://johnwargo.com)
|
|
|
43
43
|
√ Post tag? ... post
|
|
44
44
|
√ Start year for generated posts? ... 2023
|
|
45
45
|
√ Use year folder for posts? ... yes
|
|
46
|
+
√ Include timestamp in post metadata? ... yes
|
|
46
47
|
|
|
47
48
|
Settings Summary:
|
|
48
49
|
----------------------------------------
|
|
@@ -55,16 +56,16 @@ Output folder: D:\dev\node\11ty-generate-posts\posts
|
|
|
55
56
|
|
|
56
57
|
Generating posts...
|
|
57
58
|
----------------------------------------
|
|
58
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\navigator-washbasin-dramatize-landside-sensation.md
|
|
59
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\amusing-peculiar-surgical-borough-impotency-surround-tubular.md
|
|
60
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\maturely-convene-squishier-verify.md
|
|
61
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\matchless-overlaid-expend-oxidation-tribesman.md
|
|
62
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\basis-brunt-swaddling-ladylike-support-epidemic-graded.md
|
|
63
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\certify-unsheathe-undress-obstacle-tweak-tray-ridden.md
|
|
64
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\matching-enjoying-contact-atlas.md
|
|
65
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\android-gecko-penalize-possum.md
|
|
66
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\contempt-acquire-filtrate-defense-ergonomic-acts.md
|
|
67
|
-
Writing: D:\dev\node\11ty-generate-posts\posts\2023\splinter-ecology-computer-nearby-shorts-feminize.md
|
|
59
|
+
[ 1] Writing: D:\dev\node\11ty-generate-posts\posts\2023\navigator-washbasin-dramatize-landside-sensation.md
|
|
60
|
+
[ 2] Writing: D:\dev\node\11ty-generate-posts\posts\2023\amusing-peculiar-surgical-borough-impotency-surround-tubular.md
|
|
61
|
+
[ 3] Writing: D:\dev\node\11ty-generate-posts\posts\2023\maturely-convene-squishier-verify.md
|
|
62
|
+
[ 4] Writing: D:\dev\node\11ty-generate-posts\posts\2023\matchless-overlaid-expend-oxidation-tribesman.md
|
|
63
|
+
[ 5] Writing: D:\dev\node\11ty-generate-posts\posts\2023\basis-brunt-swaddling-ladylike-support-epidemic-graded.md
|
|
64
|
+
[ 6] Writing: D:\dev\node\11ty-generate-posts\posts\2023\certify-unsheathe-undress-obstacle-tweak-tray-ridden.md
|
|
65
|
+
[ 7] Writing: D:\dev\node\11ty-generate-posts\posts\2023\matching-enjoying-contact-atlas.md
|
|
66
|
+
[ 8] Writing: D:\dev\node\11ty-generate-posts\posts\2023\android-gecko-penalize-possum.md
|
|
67
|
+
[ 9] Writing: D:\dev\node\11ty-generate-posts\posts\2023\contempt-acquire-filtrate-defense-ergonomic-acts.md
|
|
68
|
+
[10] Writing: D:\dev\node\11ty-generate-posts\posts\2023\splinter-ecology-computer-nearby-shorts-feminize.md
|
|
68
69
|
```
|
|
69
70
|
|
|
70
71
|
Configuration options are:
|
|
@@ -74,6 +75,7 @@ Configuration options are:
|
|
|
74
75
|
* **Post Tag:** The front matter `tag` property applied to the generated posts
|
|
75
76
|
* **Start Year:** The starting year used for post date in the generated posts. The command uses the current date or the current date with the specified year (when provided) to for the post date for the first generated post. For subsequent post dates, the command randomly decrements the day.
|
|
76
77
|
* **Use Year Folder:** specifies whether the module writes generated posts to the Posts folder (`N`) or into a separate folder for each year (`Y`).
|
|
78
|
+
* **Timestamp** Adds a `timestamp` property (`timestamp: 2026-01-13T12:13:16.979Z`) to generated post frontmatter. On many of my sites, I display the `timestamp` for posts instead of the `date` property; this allows me to sort posts by creation time as well as date.
|
|
77
79
|
|
|
78
80
|
Obviously if you generate enough posts to push into the previous year, the posts will save into a folder for the previous year.
|
|
79
81
|
|
|
@@ -91,8 +93,9 @@ A sample generated post looks like the following:
|
|
|
91
93
|
```markdown
|
|
92
94
|
---
|
|
93
95
|
title: Boaster Halogen Jokingly Evident Decode Steadfast
|
|
94
|
-
date:
|
|
96
|
+
date: 2026-01-13
|
|
95
97
|
tags: post
|
|
98
|
+
timestamp: 2026-01-13T12:13:16.979Z
|
|
96
99
|
---
|
|
97
100
|
|
|
98
101
|
Bacon ipsum dolor amet brisket picanha swine beef ribs pork. Pig short ribs andouille ham ribeye hamburger
|