Skip to content

Commit

Permalink
Convert to work with Postgres for Kubernetes repo
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-heyer committed Jun 30, 2022
1 parent c5a4a74 commit c344cf1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
4 changes: 0 additions & 4 deletions scripts/fileProcessor/processors/cnp/add-frontmatters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const getFrontmatter = async (header, filename) => {
let frontmatter = `---
title: '${header}'
originalFilePath: '${filename}'
product: 'Cloud Native Operator'
`;

if (filename.slice(-8) === "index.md") {
Expand All @@ -44,9 +43,6 @@ const addIndexFrontmatterSection = async (frontmatter) => {
let modifiedFrontmatter =
frontmatter +
`indexCards: none
directoryDefaults:
prevNext: true
iconName: logos/KubernetesMono
navigation:
`;
Expand Down
19 changes: 12 additions & 7 deletions scripts/fileProcessor/processors/cnp/update-yaml-links.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ import visit from "unist-util-visit";
import isAbsoluteUrl from "is-absolute-url";

export const process = async (filename, content) => {

const processor = unified()
.use(remarkParse)
.use(remarkStringify, { emphasis: "*", bullet: "-", fences: true })
.use(admonitions, {
tag: "!!!", icons: "none", infima: true, customTypes: {
seealso: "note", hint: "tip", interactive: "interactive",
}
tag: "!!!",
icons: "none",
infima: true,
customTypes: {
seealso: "note",
hint: "tip",
interactive: "interactive",
},
})
.use(remarkFrontmatter)
.use(mdx)
.use(linkRewriter);

const output = await processor.process(toVFile({ path: filename, contents: content }));
const output = await processor.process(
toVFile({ path: filename, contents: content }),
);

return {
newFilename: filename,
Expand All @@ -32,12 +38,11 @@ export const process = async (filename, content) => {

function linkRewriter() {
return (tree) => {

// link rewriter:
// - only links to .yaml files in samples dir
// - make relative to parent (because gatsby URL paths are always directories)
visit(tree, "link", (node) => {
if (isAbsoluteUrl(node.url) || node.url[0] === '/') return;
if (isAbsoluteUrl(node.url) || node.url[0] === "/") return;
if (!node.url.includes(".yaml")) return;
node.url = node.url.replace(/^(?:\.\/)?samples\//, "../samples/");
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/source/dispatch_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
args = parser.parse_args()

commands = {
"EnterpriseDB/cloud-native-postgresql": f"{args.workspace}/destination/scripts/source/process-cnp-docs.sh {args.workspace}/source {args.workspace }/destination",
"EnterpriseDB/cloud-native-postgres": f"{args.workspace}/destination/scripts/source/process-cnp-docs.sh {args.workspace}/source {args.workspace }/destination",
"EnterpriseDB/fe": f"mkdir -p {args.workspace}/destination/icons-pkg && \
cp -fr utils/icons-placeholder/output/* {args.workspace}/destination/icons-pkg/",
"EnterpriseDB/LiveCompare": f"node {args.workspace}/destination/scripts/source/livecompare.js {args.workspace}/source {args.workspace}/destination --unhandled-rejections=strict",
Expand Down
62 changes: 62 additions & 0 deletions scripts/source/files-to-ignore.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// List the files to ignore when merging sourced docs
// Ignored files are those that were not previously sourced - those without an originalFilePath key in their frontmatter
// note that this does not allow for merging docs-native images or sample files currently. Consider that a TODO

import remarkParse from "remark-parse";
import mdx from "remark-mdx";
import unified from "unified";
import remarkFrontmatter from "remark-frontmatter";
import yaml from "js-yaml";
import admonitions from "remark-admonitions";
import visit from "unist-util-visit";
import { globby } from "globby";
import toVfile from "to-vfile";
import path from "path";
const { read } = toVfile;

(async () => {
if (!process.argv[2]) {
console.log(`usage:
${process.argv[1]} <path>
example:
${process.argv[1]} "product_docs/docs/cloud-native-postgres/1/"`);
return;
}

const parser = unified()
.use(remarkParse)
.use(admonitions, {
tag: "!!!",
icons: "none",
infima: true,
customTypes: {
seealso: "note",
hint: "tip",
interactive: "interactive",
},
})
.use(mdx)
.use(remarkFrontmatter);
const indexing = unified().use(searcher);

const mdxesToIndex = await globby(path.join(process.argv[2], "**", "*.mdx"));

// indexing
for (const mdxPath of mdxesToIndex) {
const file = await read(mdxPath);
const ast = await parser.parse(file);
await indexing.run(ast, file);
}
})();

function searcher() {
return (tree, file) => {
visit(tree, "yaml", (node) => {
const frontmatter = yaml.load(node.value);

if (!frontmatter.originalFilePath)
console.log("- " + path.relative(process.argv[2], file.path));
});
};
}
8 changes: 6 additions & 2 deletions scripts/source/process-cnp-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ DESTINATION_CHECKOUT=`cd $2 && pwd`
cd $DESTINATION_CHECKOUT/scripts/fileProcessor
npm install --production

cd $DESTINATION_CHECKOUT/product_docs/docs/postgres_for_kubernetes/1/
node $DESTINATION_CHECKOUT/scripts/source/files-to-ignore.mjs \
"$DESTINATION_CHECKOUT/product_docs/docs/postgres_for_kubernetes/1/" \
> $SOURCE_CHECKOUT/files-to-ignore.txt

cd $SOURCE_CHECKOUT/docs

node $DESTINATION_CHECKOUT/scripts/fileProcessor/main.mjs \
Expand All @@ -25,5 +30,4 @@ node $DESTINATION_CHECKOUT/scripts/fileProcessor/main.mjs \
-p "cnp/add-frontmatters" \
-p "cnp/rename-to-mdx"

rsync -a --delete src/ $DESTINATION_CHECKOUT/advocacy_docs/kubernetes/cloud_native_postgresql/
cp $DESTINATION_CHECKOUT/merge_sources/kubernetes/cloud_native_postgresql/interactive_demo.mdx $DESTINATION_CHECKOUT/advocacy_docs/kubernetes/cloud_native_postgresql/interactive_demo.mdx
rsync -av --delete --exclude-from=$SOURCE_CHECKOUT/files-to-ignore.txt src/ $DESTINATION_CHECKOUT/product_docs/docs/postgres_for_kubernetes/1/

0 comments on commit c344cf1

Please sign in to comment.