quackage 1.0.67 → 1.0.68

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quackage",
3
- "version": "1.0.67",
3
+ "version": "1.0.68",
4
4
  "description": "Building. Testing. Quacking. Reloading.",
5
5
  "main": "source/Quackage-CLIProgram.js",
6
6
  "scripts": {
@@ -179,6 +179,91 @@ class QuackageCommandPrepareDocs extends libCommandLineCommand
179
179
  );
180
180
  }.bind(this));
181
181
 
182
+ // Step 5: Stamp meaningful <title> and <meta name="description">
183
+ // into the freshly-injected index.html so social-card scrapers
184
+ // (Slack, etc.) read the module name + version instead of the
185
+ // generic "powered by pict-docuserve" boilerplate.
186
+ tmpAnticipate.anticipate(
187
+ function (fNext)
188
+ {
189
+ this.log.info(`###############################[ STEP 5: STAMP HTML METADATA ]###############################`);
190
+ try
191
+ {
192
+ let tmpIndexPath = libPath.join(tmpDocsFolder, 'index.html');
193
+ if (!libFS.existsSync(tmpIndexPath))
194
+ {
195
+ this.log.warn(`No index.html at [${tmpIndexPath}]; skipping metadata stamp.`);
196
+ return fNext();
197
+ }
198
+
199
+ let tmpVersionPath = libPath.join(tmpDocsFolder, '_version.json');
200
+ let tmpVersion = null;
201
+ if (libFS.existsSync(tmpVersionPath))
202
+ {
203
+ try { tmpVersion = JSON.parse(libFS.readFileSync(tmpVersionPath, 'utf8')); }
204
+ catch (e) { this.log.warn(`Could not parse _version.json: ${e.message}`); }
205
+ }
206
+
207
+ // Prefer the H1 from _cover.md as the display name (it
208
+ // has been hand-curated with proper casing and spacing);
209
+ // fall back to package.json name from _version.json.
210
+ let tmpDisplayName = '';
211
+ let tmpCoverPath = libPath.join(tmpDocsFolder, '_cover.md');
212
+ if (libFS.existsSync(tmpCoverPath))
213
+ {
214
+ let tmpCoverText = libFS.readFileSync(tmpCoverPath, 'utf8');
215
+ let tmpH1Match = tmpCoverText.match(/^#\s+(.+?)\s*$/m);
216
+ if (tmpH1Match)
217
+ {
218
+ tmpDisplayName = tmpH1Match[1].trim();
219
+ }
220
+ }
221
+ if (!tmpDisplayName && tmpVersion && tmpVersion.Name)
222
+ {
223
+ tmpDisplayName = tmpVersion.Name;
224
+ }
225
+ if (!tmpDisplayName)
226
+ {
227
+ this.log.warn(`No display name available (no _cover.md H1 and no _version.json); leaving stock metadata.`);
228
+ return fNext();
229
+ }
230
+
231
+ let tmpVersionString = (tmpVersion && tmpVersion.Version) ? ` v${tmpVersion.Version}` : '';
232
+ let tmpTitle = `${tmpDisplayName}${tmpVersionString} Documentation`;
233
+ let tmpDescription = tmpTitle;
234
+ if (tmpVersion && tmpVersion.Description)
235
+ {
236
+ tmpDescription = `${tmpTitle} — ${tmpVersion.Description}`;
237
+ }
238
+
239
+ let tmpHTML = libFS.readFileSync(tmpIndexPath, 'utf8');
240
+
241
+ // Escape for HTML attribute / element text contexts.
242
+ let fHTMLEscape = (pText) => String(pText)
243
+ .replace(/&/g, '&amp;')
244
+ .replace(/</g, '&lt;')
245
+ .replace(/>/g, '&gt;')
246
+ .replace(/"/g, '&quot;');
247
+
248
+ tmpHTML = tmpHTML.replace(
249
+ /<title>[\s\S]*?<\/title>/i,
250
+ `<title>${fHTMLEscape(tmpTitle)}</title>`
251
+ );
252
+ tmpHTML = tmpHTML.replace(
253
+ /<meta\s+name="description"\s+content="[^"]*"\s*\/?>/i,
254
+ `<meta name="description" content="${fHTMLEscape(tmpDescription)}">`
255
+ );
256
+
257
+ libFS.writeFileSync(tmpIndexPath, tmpHTML);
258
+ this.log.info(`Stamped index.html metadata: "${tmpTitle}"`);
259
+ }
260
+ catch (pError)
261
+ {
262
+ this.log.warn(`Failed to stamp index.html metadata: ${pError.message}`);
263
+ }
264
+ return fNext();
265
+ }.bind(this));
266
+
182
267
  return tmpAnticipate.wait(
183
268
  function (pError)
184
269
  {