kss-modern 1.5.0 → 1.6.0

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.
@@ -153,6 +153,15 @@ interface StyleguideOptions {
153
153
  * the initial page load.
154
154
  */
155
155
  reloadPreviewsOnThemeChange?: boolean;
156
+ /**
157
+ * Let search engines index the generated styleguide.
158
+ *
159
+ * Off by default: a styleguide is internal documentation, and its output directory is usually
160
+ * served from a host that is reachable without being meant for the public. Every build writes a
161
+ * `robots.txt` into the output root, and every page carries a matching `<meta name="robots">` —
162
+ * `noindex, nofollow` while this is off, `index, follow` once it is on.
163
+ */
164
+ allowSearchEngineIndexing?: boolean;
156
165
  logoSignet?: {
157
166
  href: string;
158
167
  } | {
@@ -153,6 +153,15 @@ interface StyleguideOptions {
153
153
  * the initial page load.
154
154
  */
155
155
  reloadPreviewsOnThemeChange?: boolean;
156
+ /**
157
+ * Let search engines index the generated styleguide.
158
+ *
159
+ * Off by default: a styleguide is internal documentation, and its output directory is usually
160
+ * served from a host that is reachable without being meant for the public. Every build writes a
161
+ * `robots.txt` into the output root, and every page carries a matching `<meta name="robots">` —
162
+ * `noindex, nofollow` while this is off, `index, follow` once it is on.
163
+ */
164
+ allowSearchEngineIndexing?: boolean;
156
165
  logoSignet?: {
157
166
  href: string;
158
167
  } | {
@@ -1344,6 +1344,18 @@ async function logicalWriteFile(filepath, content) {
1344
1344
  await fs.writeFile(filepath, content);
1345
1345
  }
1346
1346
 
1347
+ const ROBOTS_FILE_NAME = "robots.txt";
1348
+ function generateRobotsTxt(allowSearchEngineIndexing) {
1349
+ const rule = allowSearchEngineIndexing ? "Allow: /" : "Disallow: /";
1350
+ return `# Generated by kss-modern
1351
+ User-agent: *
1352
+ ${rule}
1353
+ `;
1354
+ }
1355
+ async function writeRobotsFile(outDir, allowSearchEngineIndexing) {
1356
+ await logicalWriteFile(path.join(outDir, ROBOTS_FILE_NAME), generateRobotsTxt(allowSearchEngineIndexing));
1357
+ }
1358
+
1347
1359
  async function generateFullPageFile(data) {
1348
1360
  const supportsDarkMode = !(data.deactivateDarkMode ?? false);
1349
1361
  const computedScriptTags = data.js.filter((entry) => entry.type !== "overwriteStyleguide").map((js) => {
@@ -1363,6 +1375,7 @@ async function generateFullPageFile(data) {
1363
1375
  <meta charset="UTF-8">
1364
1376
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1365
1377
  <meta name="generator" content="styleguide">
1378
+ <meta name="robots" content="${data.allowSearchEngineIndexing ? "index, follow" : "noindex, nofollow"}">
1366
1379
  <link rel="icon" type="image/svg+xml" href="/styleguide-assets/favicon/fullpage.svg">
1367
1380
  ${data.ogImageUrl ? `<meta property="og:image" content="${data.ogImageUrl}">` : ""}
1368
1381
  ${typeof data.brandColor === "object" && "dark" in data.brandColor && "light" in data.brandColor ? `
@@ -2228,6 +2241,7 @@ async function generatePreviewFile(data) {
2228
2241
  <meta charset="UTF-8">
2229
2242
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
2230
2243
  <meta name="generator" content="styleguide">
2244
+ <meta name="robots" content="${data.allowSearchEngineIndexing ? "index, follow" : "noindex, nofollow"}">
2231
2245
  <link rel="icon" type="image/svg+xml" href="/styleguide-assets/favicon/preview.svg">
2232
2246
  ${data.ogImageUrl ? `<meta property="og:image" content="${data.ogImageUrl}">` : ""}
2233
2247
  ${typeof data.brandColor === "object" && "dark" in data.brandColor && "light" in data.brandColor ? `
@@ -2693,6 +2707,7 @@ async function writeFullPageFile(config, baseDirectory, section) {
2693
2707
  html: htmlMarkup,
2694
2708
  brandColor: config.brandColor,
2695
2709
  deactivateDarkMode: config.deactivateDarkMode,
2710
+ allowSearchEngineIndexing: config.allowSearchEngineIndexing,
2696
2711
  ogImageUrl: config.plugins?.ogImage ? config.plugins.ogImage(section) : void 0
2697
2712
  });
2698
2713
  } catch (error) {
@@ -2750,6 +2765,7 @@ function writePreviewFile(config, context, firstLevelIndex, secondLevelIndex) {
2750
2765
  },
2751
2766
  brandColor: config.brandColor,
2752
2767
  deactivateDarkMode: config.deactivateDarkMode,
2768
+ allowSearchEngineIndexing: config.allowSearchEngineIndexing,
2753
2769
  reloadPreviewsOnThemeChange: config.reloadPreviewsOnThemeChange,
2754
2770
  ogImageUrl: config.plugins?.ogImage ? config.plugins.ogImage(secondLevelSection) : void 0
2755
2771
  });
@@ -2886,7 +2902,11 @@ async function buildAll(input) {
2886
2902
  fileWriteTasks.push(writePreviewFile(config, context, firstLevelIndex, secondLevelIndex));
2887
2903
  });
2888
2904
  });
2889
- await Promise.all([copyStyleguideAssets(config), ...fileWriteTasks]);
2905
+ await Promise.all([
2906
+ copyStyleguideAssets(config),
2907
+ writeRobotsFile(config.outDir, config.allowSearchEngineIndexing ?? false),
2908
+ ...fileWriteTasks
2909
+ ]);
2890
2910
  const errors = {};
2891
2911
  if (context.overwrittenSectionsIds.length > 0) {
2892
2912
  errors.overwrittenSectionsIds = context.overwrittenSectionsIds;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kss-modern",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "description": "Modern KSS compatible styleguide generator",
6
6
  "keywords": [
7
7
  "kss",