kss-modern 1.5.0 → 1.6.1
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
|
} | {
|
package/dist/node/lib/index.d.ts
CHANGED
|
@@ -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
|
} | {
|
package/dist/node/lib/index.mjs
CHANGED
|
@@ -792,12 +792,13 @@ function extractMarkdownPath(input) {
|
|
|
792
792
|
}
|
|
793
793
|
return path2;
|
|
794
794
|
}
|
|
795
|
+
function compareReferences(a, b) {
|
|
796
|
+
return a.localeCompare(b, void 0, { numeric: true });
|
|
797
|
+
}
|
|
795
798
|
async function parse(input, contentDir) {
|
|
796
799
|
const data = kssParser(input).sections.filter((section) => Boolean(section.reference));
|
|
797
800
|
const overwrittenSectionsIds = [];
|
|
798
|
-
const sortedData = data.sort((a, b) =>
|
|
799
|
-
return a.reference.localeCompare(b.reference);
|
|
800
|
-
});
|
|
801
|
+
const sortedData = data.sort((a, b) => compareReferences(a.reference, b.reference));
|
|
801
802
|
let output = [];
|
|
802
803
|
async function computeDescription(description, rootHeadingLevel) {
|
|
803
804
|
if (!description || !description.includes("Markdown:"))
|
|
@@ -960,7 +961,7 @@ async function parse(input, contentDir) {
|
|
|
960
961
|
output.forEach((firstLevelSection) => {
|
|
961
962
|
firstLevelSection.sections = firstLevelSection.sections.filter((section) => Boolean(section));
|
|
962
963
|
firstLevelSection.sections.forEach((secondLevelSection) => {
|
|
963
|
-
secondLevelSection.sections = secondLevelSection.sections.filter((section) => Boolean(section)).sort((a, b) => a.id
|
|
964
|
+
secondLevelSection.sections = secondLevelSection.sections.filter((section) => Boolean(section)).sort((a, b) => compareReferences(a.id, b.id));
|
|
964
965
|
});
|
|
965
966
|
});
|
|
966
967
|
return {
|
|
@@ -1344,6 +1345,18 @@ async function logicalWriteFile(filepath, content) {
|
|
|
1344
1345
|
await fs.writeFile(filepath, content);
|
|
1345
1346
|
}
|
|
1346
1347
|
|
|
1348
|
+
const ROBOTS_FILE_NAME = "robots.txt";
|
|
1349
|
+
function generateRobotsTxt(allowSearchEngineIndexing) {
|
|
1350
|
+
const rule = allowSearchEngineIndexing ? "Allow: /" : "Disallow: /";
|
|
1351
|
+
return `# Generated by kss-modern
|
|
1352
|
+
User-agent: *
|
|
1353
|
+
${rule}
|
|
1354
|
+
`;
|
|
1355
|
+
}
|
|
1356
|
+
async function writeRobotsFile(outDir, allowSearchEngineIndexing) {
|
|
1357
|
+
await logicalWriteFile(path.join(outDir, ROBOTS_FILE_NAME), generateRobotsTxt(allowSearchEngineIndexing));
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1347
1360
|
async function generateFullPageFile(data) {
|
|
1348
1361
|
const supportsDarkMode = !(data.deactivateDarkMode ?? false);
|
|
1349
1362
|
const computedScriptTags = data.js.filter((entry) => entry.type !== "overwriteStyleguide").map((js) => {
|
|
@@ -1363,6 +1376,7 @@ async function generateFullPageFile(data) {
|
|
|
1363
1376
|
<meta charset="UTF-8">
|
|
1364
1377
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1365
1378
|
<meta name="generator" content="styleguide">
|
|
1379
|
+
<meta name="robots" content="${data.allowSearchEngineIndexing ? "index, follow" : "noindex, nofollow"}">
|
|
1366
1380
|
<link rel="icon" type="image/svg+xml" href="/styleguide-assets/favicon/fullpage.svg">
|
|
1367
1381
|
${data.ogImageUrl ? `<meta property="og:image" content="${data.ogImageUrl}">` : ""}
|
|
1368
1382
|
${typeof data.brandColor === "object" && "dark" in data.brandColor && "light" in data.brandColor ? `
|
|
@@ -2228,6 +2242,7 @@ async function generatePreviewFile(data) {
|
|
|
2228
2242
|
<meta charset="UTF-8">
|
|
2229
2243
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
2230
2244
|
<meta name="generator" content="styleguide">
|
|
2245
|
+
<meta name="robots" content="${data.allowSearchEngineIndexing ? "index, follow" : "noindex, nofollow"}">
|
|
2231
2246
|
<link rel="icon" type="image/svg+xml" href="/styleguide-assets/favicon/preview.svg">
|
|
2232
2247
|
${data.ogImageUrl ? `<meta property="og:image" content="${data.ogImageUrl}">` : ""}
|
|
2233
2248
|
${typeof data.brandColor === "object" && "dark" in data.brandColor && "light" in data.brandColor ? `
|
|
@@ -2693,6 +2708,7 @@ async function writeFullPageFile(config, baseDirectory, section) {
|
|
|
2693
2708
|
html: htmlMarkup,
|
|
2694
2709
|
brandColor: config.brandColor,
|
|
2695
2710
|
deactivateDarkMode: config.deactivateDarkMode,
|
|
2711
|
+
allowSearchEngineIndexing: config.allowSearchEngineIndexing,
|
|
2696
2712
|
ogImageUrl: config.plugins?.ogImage ? config.plugins.ogImage(section) : void 0
|
|
2697
2713
|
});
|
|
2698
2714
|
} catch (error) {
|
|
@@ -2750,6 +2766,7 @@ function writePreviewFile(config, context, firstLevelIndex, secondLevelIndex) {
|
|
|
2750
2766
|
},
|
|
2751
2767
|
brandColor: config.brandColor,
|
|
2752
2768
|
deactivateDarkMode: config.deactivateDarkMode,
|
|
2769
|
+
allowSearchEngineIndexing: config.allowSearchEngineIndexing,
|
|
2753
2770
|
reloadPreviewsOnThemeChange: config.reloadPreviewsOnThemeChange,
|
|
2754
2771
|
ogImageUrl: config.plugins?.ogImage ? config.plugins.ogImage(secondLevelSection) : void 0
|
|
2755
2772
|
});
|
|
@@ -2886,7 +2903,11 @@ async function buildAll(input) {
|
|
|
2886
2903
|
fileWriteTasks.push(writePreviewFile(config, context, firstLevelIndex, secondLevelIndex));
|
|
2887
2904
|
});
|
|
2888
2905
|
});
|
|
2889
|
-
await Promise.all([
|
|
2906
|
+
await Promise.all([
|
|
2907
|
+
copyStyleguideAssets(config),
|
|
2908
|
+
writeRobotsFile(config.outDir, config.allowSearchEngineIndexing ?? false),
|
|
2909
|
+
...fileWriteTasks
|
|
2910
|
+
]);
|
|
2890
2911
|
const errors = {};
|
|
2891
2912
|
if (context.overwrittenSectionsIds.length > 0) {
|
|
2892
2913
|
errors.overwrittenSectionsIds = context.overwrittenSectionsIds;
|