eleventy-generate-posts 0.0.1 → 0.0.2

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 CHANGED
@@ -1 +1,5 @@
1
1
  # Changelog
2
+
3
+ ## 20230516
4
+
5
+ Added support for the `-y` flag which saves generated posts to a subfolder for the current year.
@@ -70,6 +70,7 @@ program
70
70
  .argument('<tag>', 'Tag to apply to all generated posts')
71
71
  .argument('[startYear]', 'Start year for generated posts')
72
72
  .option('-d, --debug', 'Debug mode')
73
+ .option('-y, --year', 'Save to Year folder')
73
74
  .action(async (numPosts, targetFolder, tag, startYear) => {
74
75
  console.log(boxen(APP_NAME, { padding: 1 }));
75
76
  console.log(APP_AUTHOR);
@@ -84,6 +85,8 @@ program
84
85
  if (startYear)
85
86
  writeConsole(yellow, 'Start Year', startYear);
86
87
  writeConsole(yellow, 'Tag', tag);
88
+ const yearMode = options.year;
89
+ writeConsole(yellow, 'Year mode', yearMode ? 'enabled' : 'disabled');
87
90
  if (!Number.isInteger(parseInt(numPosts))) {
88
91
  writeConsole(red, 'Error', 'Number of posts must be an integer');
89
92
  process.exit(1);
@@ -126,7 +129,13 @@ program
126
129
  thePost += YAML.stringify(postFm, { logLevel: 'silent' });
127
130
  thePost += '---\n\n';
128
131
  thePost += postContent.join('\n\n');
129
- var outputFilePath = path.join(targetFolder, postTitle.toLowerCase().replaceAll(' ', '-') + '.md');
132
+ var outputFilePath = path.join(process.cwd(), targetFolder);
133
+ if (yearMode) {
134
+ outputFilePath = path.join(outputFilePath, currentDate.getFullYear().toString());
135
+ if (!fs.existsSync(outputFilePath))
136
+ fs.mkdirSync(outputFilePath, { recursive: true });
137
+ }
138
+ var outputFilePath = path.join(outputFilePath, postTitle.toLowerCase().replaceAll(' ', '-') + '.md');
130
139
  writeConsole(green, 'Writing', outputFilePath);
131
140
  fs.writeFileSync(outputFilePath, thePost, 'utf8');
132
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-generate-posts",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Generates batches of Eleventy posts",
5
5
  "author": "John M. Wargo",
6
6
  "license": "MIT",
package/readme.md CHANGED
@@ -4,7 +4,7 @@ A simple command-line utility that creates a batch of new posts for an [Eleventy
4
4
 
5
5
  When you're testing out some aspect of an Eleventy site or doing a demo, you often need to populate the site with a set of posts to flesh out the site. Copying a single post or set of posts repeatedly into the site works, but an automated solution is better. This is that solution.
6
6
 
7
- The utility generates batches of Eleventy site posts, populating the post title with a random quantity of random words and populating the post body with a random number of paragraphs of [Bacon Ipsum](https://baconipsum.com/) text.
7
+ The utility generates batches of Eleventy site posts, populating the post title with a random quantity of random words using the [Rando Free Random Word Generator API](https://random-word-api.vercel.app/) and populating the post body with a random number of paragraphs of [Bacon Ipsum](https://baconipsum.com/) text.
8
8
 
9
9
  ## Installation
10
10
 
@@ -17,6 +17,7 @@ npm install -g eleventy-generate-posts
17
17
  This adds a `11ty-gp` command to the system.
18
18
 
19
19
  You don't have to install the package to use it; simply open a terminal window or command prompt to your Eleventy project folder and execute the command using `npx eleventy-generate-posts` and the command-line options described in the following section.
20
+
20
21
  ## Usage
21
22
 
22
23
  Execute the command using the following command-line parameters:
@@ -25,13 +26,19 @@ Execute the command using the following command-line parameters:
25
26
  11ty-gp [options] <numPosts> <targetFolder> <tag> [startYear]
26
27
  ```
27
28
 
28
- Supported command-line options are:
29
+ Supported command-line parameters are:
29
30
 
30
31
  * `numPosts` (required) An integer value representing the number of posts generated.
31
32
  * `targetFolder` (required) Relative path pointing to the Eleventy project's posts folder; use `.` for the current folder.
32
33
  * `tag` (required) The post tag applied to the generated posts
33
34
  * `startYear` (optional) 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.
34
35
 
36
+ Supported command-line options (flags) are:
37
+
38
+ * `-d` or `--debug`: Enables debug mode which generates additional content to the terminal during execution
39
+ * `-h` or `--help`: Displays usage information in the terminal
40
+ * `-y` or `--year`: instructs the command to store posts to a subfolder for the post date year.
41
+
35
42
  As an example, to generate 10 posts in the project's `posts` folder using a `tags` value of `post`, use:
36
43
 
37
44
  ```shell
@@ -48,10 +55,15 @@ To generate 20 posts starting in 2021, use the following:
48
55
 
49
56
  This command sets the post date for the current post to the current month/day plus the provided year, then works backwards (random days) for each subsequent generated post. So, if you execute the command on May 10, 2023, the command sets the post date for the first post to May 10, 2021 and works (randomly) backwards from there.
50
57
 
51
- Supported command-line options (flags) are:
58
+ To generate 20 posts starting in 2021 and store them in a folder for the current year (`posts/2021` in this example), use the `-y` or `--year` flag on the command line:
52
59
 
53
- * `-d` or `--debug`: Enables debug mode which generates additional content to the terminal during execution
54
- * `h` or `--help`: Displays usage information in the terminal
60
+ ```shell
61
+ 11ty-gp 20 posts post 2021 -y
62
+ ```
63
+
64
+ Obviously if you generate enough posts to push into the previous year, the posts will save into a folder for the previous year.
65
+
66
+ ## Example Post
55
67
 
56
68
  A sample generated post looks like the following:
57
69
 
@@ -73,7 +85,7 @@ pastrami burgdoggen meatball. Frankfurter kevin pig, hamburger andouille tail m
73
85
  ribs prosciutto. Meatloaf chislic flank tri-tip swine filet mignon brisket sirloin turkey porchetta.
74
86
  ```
75
87
 
76
- ### Getting Help Or Making Changes
88
+ ## Getting Help Or Making Changes
77
89
 
78
90
  Use [GitHub Issues](https://github.com/johnwargo/eleventy-generate-posts/issues) to get help with this module.
79
91