Skip to content

Commit 5fc1471

Browse files
committed
quick and dirty product name replacement
1 parent 7c7ec68 commit 5fc1471

File tree

14 files changed

+383
-473
lines changed

14 files changed

+383
-473
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "{{name.ln}} examples"
3+
navTitle: "{{name.short}}"
4+
description: "{{name.ln}} v{{version.full}} provides functionality for replacing simple expressions representing product names and versions"
5+
displayBanner: "{{name.ln}} v{{version.full}} is not a real product, but it plays one in the playground"
6+
product: "Expression Replacement"
7+
version: "1.0.1"
8+
---
9+
10+
11+
12+
This functionality allows for writing documentation when the future (or current) name of a product is subject to change. It is based on the metadata in `src/constants/products.js` combined with product names and versions (defined via either filesystem or frontmatter) and allows multiple forms of a product name as well as transformations of semantic version numbers.
13+
14+
## Example products.js data definition
15+
16+
```javascript
17+
"Expression Replacement": {
18+
name: "Name and Version Expression Replacement Syntax",
19+
shortName: "Expression Replacement",
20+
abbreviation: "ExpRel",
21+
commonCommandName: "{{name().type}}",
22+
}
23+
```
24+
25+
## Examples of invocation
26+
27+
| Expression | Replacement | Source |
28+
|---------------------------------------------------|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
29+
| `\{{name.ln}}` | {{name.ln}} | product definition - `.name` |
30+
| `\{{name.short}}` | {{name.short}} | product definition - `.shortName` |
31+
| `\{{name.abbr}}` | {{name.abbr}} | product definition - `.abbreviation` |
32+
| `\{{name.ccn}}` | {{name.ccn}} | product definition - `.commonCommandName` |
33+
| `\{{name(pgd).short}}` | {{name(pgd).short}} | PGD product definition - `.shortName` |
34+
| `\{{version.full}}` | {{version.full}} | frontmatter - `version:` |
35+
| `\{{version(pgd).short}}` | {{version(pgd).short}} | filesystem directory version for latest product version |
36+
| `\{{version(pgd).major}}.\{{version(pgd).minor}}` | {{version(pgd).major}}.{{version(pgd).minor}} | frontmatter - `version:` for latest product version. Parsed as semver, truncated at minor version |
37+
38+
## Scope
39+
40+
Expressions should be parsed in all Markdown elements containing rendered content, including code blocks and inline code. Frontmatter-sourced version information is not currently available in code.
41+
42+
Additionally, expressions will be replaced in certain frontmatter-defined values; initially, these include "title", "navTitle", "description" and "displayBanner".
43+

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ module.exports = {
380380
],
381381
remarkPlugins: [
382382
[require("./src/plugins/code-in-tables")],
383+
[require("./src/plugins/replacement-expression")],
383384
[
384385
require("remark-admonitions"),
385386
{

gatsby-node.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const { createFilePath } = require(`gatsby-source-filesystem`);
77
const { exec, execSync } = require("child_process");
88
const util = require("node:util");
99
const execAsync = util.promisify(exec);
10+
let expressionReplacement = import(
11+
"./src/constants/expression-replacement.mjs"
12+
).then((module) => (expressionReplacement = module.default));
1013

1114
const {
1215
replacePathVersion,
@@ -156,12 +159,12 @@ exports.onCreateNode = async ({
156159
Object.assign(nodeFields, {
157160
product: relativeFilePath.split("/")[1],
158161
version: relativeFilePath.split("/")[2],
159-
topic: "null",
162+
topic: "",
160163
});
161164
} else if (nodeFields.docType === "advocacy") {
162165
Object.assign(nodeFields, {
163-
product: "null",
164-
version: "0",
166+
product: "",
167+
version: "",
165168
topic: relativeFilePath.split("/")[2],
166169
});
167170
}
@@ -192,6 +195,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
192195
legacyRedirects
193196
legacyRedirectsGenerated
194197
navigation
198+
product
195199
showInteractiveBadge
196200
hideToC
197201
deepToC
@@ -292,6 +296,21 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
292296

293297
const node = curr.mdxNode;
294298

299+
// do expression replacements in frontmatter
300+
const replacementArgs = {
301+
currentProduct: node.fields.product || node.frontmatter.product,
302+
currentVersion: node.fields.version || node.frontmatter.version,
303+
currentFullVersion: node.frontmatter.version,
304+
productVersions,
305+
filename: node.fileAbsolutePath,
306+
};
307+
for (let fmk of ["title", "navTitle", "description", "displayBanner"]) {
308+
node.frontmatter[fmk] = expressionReplacement({
309+
text: node.frontmatter[fmk],
310+
...replacementArgs,
311+
});
312+
}
313+
295314
// build navigation tree
296315
const navigationDepth = 1;
297316
let navRoot = curr;

0 commit comments

Comments
 (0)