Skip to content

Commit 236e249

Browse files
committed
add archive component
Former-commit-id: b6184cb
1 parent e8f5522 commit 236e249

File tree

8 files changed

+144
-88
lines changed

8 files changed

+144
-88
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ We recommend using MacOS to work with the EDB Docs application.
2020

2121
1. Navigate to the cloned repo directory in your Terminal, if you haven't already done so.
2222

23+
1. Create a `.env` file: `cp env .env.development`.
24+
2325
1. Install [Node.js version 14 LTS](https://nodejs.org/en/download/). We recommend using Node version 14 LTS (the Long Term Support release) as version 15 is not compatible with some of our dependencies at this time.
2426

2527
- If you already have Node installed, you can verify your version by running `node -v` in the cloned repo directory.

env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GATSBY_ENVIRONMENT_BRANCH=develop

gatsby-node.js

+53-47
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// this patch is required to consistently load all the doc files
2-
const realFs = require('fs');
3-
const gracefulFs = require('graceful-fs');
2+
const realFs = require("fs");
3+
const path = require("path");
4+
const gracefulFs = require("graceful-fs");
45
gracefulFs.gracefulify(realFs);
56

67
const { createFilePath } = require(`gatsby-source-filesystem`);
7-
const { exec, execSync } = require('child_process');
8+
const { exec, execSync } = require("child_process");
89

910
const {
1011
replacePathVersion,
@@ -23,16 +24,16 @@ const {
2324
configureLegacyRedirects,
2425
readFile,
2526
writeFile,
26-
} = require('./src/constants/gatsby-utils.js');
27+
} = require("./src/constants/gatsby-utils.js");
2728

28-
const isBuild = process.env.NODE_ENV === 'production';
29-
const isProduction = process.env.APP_ENV === 'production';
29+
const isBuild = process.env.NODE_ENV === "production";
30+
const isProduction = process.env.APP_ENV === "production";
3031

3132
exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => {
3233
const { createNodeField } = actions;
3334

34-
if (node.internal.mediaType === 'text/yaml') loadNodeContent(node);
35-
if (node.internal.type !== 'Mdx') return;
35+
if (node.internal.mediaType === "text/yaml") loadNodeContent(node);
36+
if (node.internal.type !== "Mdx") return;
3637

3738
const fileNode = getNode(node.parent);
3839
const nodeFields = {
@@ -41,7 +42,7 @@ exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => {
4142
};
4243

4344
let relativeFilePath = createFilePath({ node, getNode });
44-
if (nodeFields.docType === 'doc') {
45+
if (nodeFields.docType === "doc") {
4546
relativeFilePath = `/${fileNode.sourceInstanceName}${relativeFilePath}`;
4647
}
4748

@@ -50,17 +51,17 @@ exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => {
5051
depth: pathToDepth(relativeFilePath),
5152
});
5253

53-
if (nodeFields.docType === 'doc') {
54+
if (nodeFields.docType === "doc") {
5455
Object.assign(nodeFields, {
55-
product: relativeFilePath.split('/')[1],
56-
version: relativeFilePath.split('/')[2],
57-
topic: 'null',
56+
product: relativeFilePath.split("/")[1],
57+
version: relativeFilePath.split("/")[2],
58+
topic: "null",
5859
});
59-
} else if (nodeFields.docType === 'advocacy') {
60+
} else if (nodeFields.docType === "advocacy") {
6061
Object.assign(nodeFields, {
61-
product: 'null',
62-
version: '0',
63-
topic: relativeFilePath.split('/')[2],
62+
product: "null",
63+
version: "0",
64+
topic: relativeFilePath.split("/")[2],
6465
});
6566
}
6667

@@ -128,7 +129,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
128129
`);
129130

130131
if (result.errors) {
131-
reporter.panic('createPages graphql query has errors!', result.errors);
132+
reporter.panic("createPages graphql query has errors!", result.errors);
132133
}
133134

134135
processFileNodes(result.data.allFile.nodes, actions);
@@ -139,7 +140,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
139140

140141
// it should be possible to remove these in the future,
141142
// they are only used for navLinks generation
142-
const learn = nodes.filter((file) => file.fields.docType === 'advocacy');
143+
const learn = nodes.filter((file) => file.fields.docType === "advocacy");
143144

144145
// perform depth first preorder traversal
145146
const treeRoot = mdxNodesToTree(nodes);
@@ -155,17 +156,17 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
155156
const addedChildPaths = {};
156157
curr.navigationNodes = [];
157158
(curr.mdxNode?.frontmatter?.navigation || []).forEach((navEntry) => {
158-
if (navEntry.startsWith('#')) {
159+
if (navEntry.startsWith("#")) {
159160
curr.navigationNodes.push({
160161
path: null,
161-
title: navEntry.replace('#', '').trim(),
162+
title: navEntry.replace("#", "").trim(),
162163
});
163164
return;
164165
}
165166

166167
const navChild = curr.children.find((child) => {
167168
if (addedChildPaths[child.path]) return false;
168-
const navName = child.path.split('/').slice(-2)[0];
169+
const navName = child.path.split("/").slice(-2)[0];
169170
return navName.toLowerCase() === navEntry.toLowerCase();
170171
});
171172
if (!navChild?.mdxNode) return;
@@ -203,9 +204,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
203204
const prevNext = findPrevNextNavNodes(navTree, curr);
204205

205206
const { docType } = node.fields;
206-
if (docType === 'doc') {
207+
if (docType === "doc") {
207208
createDoc(navTree, prevNext, node, productVersions, actions);
208-
} else if (docType === 'advocacy') {
209+
} else if (docType === "advocacy") {
209210
createAdvocacy(navTree, prevNext, node, learn, actions);
210211
}
211212
}
@@ -237,18 +238,18 @@ const createDoc = (navTree, prevNext, doc, productVersions, actions) => {
237238
}
238239

239240
const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath);
240-
const docsRepoUrl = 'https://github.com/EnterpriseDB/docs';
241-
const branch = isProduction ? 'main' : 'develop';
241+
const docsRepoUrl = "https://github.com/EnterpriseDB/docs";
242+
const branch = isProduction ? "main" : "develop";
242243
const fileUrlSegment =
243244
removeTrailingSlash(doc.fields.path) +
244-
(isIndexPage ? '/index.mdx' : '.mdx');
245+
(isIndexPage ? "/index.mdx" : ".mdx");
245246
const githubFileLink = `${docsRepoUrl}/commits/${branch}/product_docs/docs${fileUrlSegment}`;
246247
const githubEditLink = `${docsRepoUrl}/edit/${branch}/product_docs/docs${fileUrlSegment}`;
247248
const githubIssuesLink = `${docsRepoUrl}/issues/new?title=Feedback%20on%20${encodeURIComponent(
248249
fileUrlSegment,
249250
)}`;
250251

251-
const template = doc.frontmatter.productStub ? 'doc-stub.js' : 'doc.js';
252+
const template = doc.frontmatter.productStub ? "doc-stub.js" : "doc.js";
252253
const path = isLatest ? replacePathVersion(doc.fields.path) : doc.fields.path;
253254

254255
// workaround for https://github.com/gatsbyjs/gatsby/issues/26520
@@ -296,12 +297,12 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
296297
(node) => node.fields.topic === doc.fields.topic,
297298
);
298299

299-
const advocacyDocsRepoUrl = 'https://github.com/EnterpriseDB/docs';
300-
const branch = isProduction ? 'main' : 'develop';
300+
const advocacyDocsRepoUrl = "https://github.com/EnterpriseDB/docs";
301+
const branch = isProduction ? "main" : "develop";
301302
const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath);
302303
const fileUrlSegment =
303304
removeTrailingSlash(doc.fields.path) +
304-
(isIndexPage ? '/index.mdx' : '.mdx');
305+
(isIndexPage ? "/index.mdx" : ".mdx");
305306
const githubFileLink = `${advocacyDocsRepoUrl}/commits/${branch}/advocacy_docs${fileUrlSegment}`;
306307
const githubEditLink = `${advocacyDocsRepoUrl}/edit/${branch}/advocacy_docs${fileUrlSegment}`;
307308
const githubIssuesLink = `${advocacyDocsRepoUrl}/issues/new?title=Regarding%20${encodeURIComponent(
@@ -311,13 +312,13 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
311312
// workaround for https://github.com/gatsbyjs/gatsby/issues/26520
312313
actions.createPage({
313314
path: doc.fields.path,
314-
component: require.resolve('./src/templates/learn-doc.js'),
315+
component: require.resolve("./src/templates/learn-doc.js"),
315316
context: {},
316317
});
317318

318319
actions.createPage({
319320
path: doc.fields.path,
320-
component: require.resolve('./src/templates/learn-doc.js'),
321+
component: require.resolve("./src/templates/learn-doc.js"),
321322
context: {
322323
nodeId: doc.id,
323324
frontmatter: doc.frontmatter,
@@ -342,7 +343,7 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
342343
const path = `${doc.fields.path}${katacodaPage.scenario}`;
343344
actions.createPage({
344345
path: path,
345-
component: require.resolve('./src/templates/katacoda-page.js'),
346+
component: require.resolve("./src/templates/katacoda-page.js"),
346347
context: {
347348
...katacodaPage,
348349
pagePath: path,
@@ -359,7 +360,7 @@ const processFileNodes = (fileNodes, actions) => {
359360
fileNodes.forEach((node) => {
360361
actions.createPage({
361362
path: node.relativePath,
362-
component: require.resolve('./src/templates/file.js'),
363+
component: require.resolve("./src/templates/file.js"),
363364
context: {
364365
nodeId: node.id,
365366
},
@@ -375,13 +376,13 @@ exports.sourceNodes = async ({
375376
// create edb-git node
376377
const sha = (
377378
await new Promise((resolve, reject) => {
378-
exec('git rev-parse HEAD', (error, stdout, stderr) => resolve(stdout));
379+
exec("git rev-parse HEAD", (error, stdout, stderr) => resolve(stdout));
379380
})
380381
).trim();
381382

382383
const branch = (
383384
await new Promise((resolve, reject) => {
384-
exec('git branch --show-current', (error, stdout, stderr) =>
385+
exec("git branch --show-current", (error, stdout, stderr) =>
385386
resolve(stdout),
386387
);
387388
})
@@ -390,9 +391,9 @@ exports.sourceNodes = async ({
390391
const gitData = { sha, branch };
391392
createNode({
392393
...gitData,
393-
id: createNodeId('edb-git'),
394+
id: createNodeId("edb-git"),
394395
internal: {
395-
type: 'edbGit',
396+
type: "edbGit",
396397
contentDigest: createContentDigest(gitData),
397398
},
398399
});
@@ -424,29 +425,34 @@ exports.createSchemaCustomization = ({ actions }) => {
424425

425426
exports.onPreBootstrap = () => {
426427
console.log(`
427-
_____ ____ _____ ____
428-
| __|| \\ | __ | | \\ ___ ___ ___
428+
_____ ____ _____ ____
429+
| __|| \\ | __ | | \\ ___ ___ ___
429430
| __|| | || __ -| | | || . || _||_ -|
430431
|_____||____/ |_____| |____/ |___||___||___|
431-
432+
432433
`);
433434
};
434435

435436
exports.onPostBuild = async ({ reporter, pathPrefix }) => {
436-
const originalRedirects = await readFile('public/_redirects');
437+
realFs.copyFileSync(
438+
path.join(__dirname, "/netlify.toml"),
439+
path.join(__dirname, "/public/netlify.toml"),
440+
);
441+
442+
const originalRedirects = await readFile("public/_redirects");
437443

438444
// filter out legacyRedirects that are loaded via nginx, not netlify
439445
let filteredRedirects = originalRedirects
440-
.split('\n')
446+
.split("\n")
441447
.filter((line) => !line.startsWith(`${pathPrefix}/edb-docs/`))
442-
.join('\n');
448+
.join("\n");
443449

444450
if (filteredRedirects.length === originalRedirects.length) {
445-
reporter.warn('no redirects were filtered out, did something change?');
451+
reporter.warn("no redirects were filtered out, did something change?");
446452
}
447453

448454
await writeFile(
449-
'public/_redirects',
455+
"public/_redirects",
450456
`${filteredRedirects}\n\n# Netlify pathPrefix path rewrite\n${pathPrefix}/* /:splat 200`,
451457
);
452458
};

netlify.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[context.production]
2+
GATSBY_ENVIRONMENT_BRANCH = "main"
3+
4+
[context.deploy-preview.environment]
5+
GATSBY_ENVIRONMENT_BRANCH = "develop"
6+
7+
[context.branch-deploy]
8+
GATSBY_ENVIRONMENT_BRANCH = "develop"

src/components/archive.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
3+
import Icon from "./icon";
4+
import Link from "./link";
5+
6+
const environment = process.env.GATSBY_ENVIRONMENT_BRANCH;
7+
8+
export default function Archive({ title, path = "", ...props }) {
9+
const updatedPath = !path.startsWith('/') ? `/${path}` : path
10+
const url = `https://github.com/EnterpriseDB/docs-archive/raw/${environment}${updatedPath}`;
11+
12+
return (
13+
<Link to={url} title={title} className="w-100 d-block" {...props}>
14+
<PdfIcon /> {title}
15+
</Link>
16+
);
17+
}
18+
19+
const PdfIcon = () => (
20+
<Icon
21+
iconName="PDF"
22+
className="fill-orange position-relative top-minus-1"
23+
width="16"
24+
height="auto"
25+
/>
26+
);

src/components/index.js

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
import BackButton from './back-button';
2-
import CardDecks from './card-decks';
3-
import CodeBlock from './code-block';
4-
import DarkModeToggle from './dark-mode-toggle';
5-
import DevOnly from './dev-only';
6-
import DevFrontmatter from './dev-frontmatter';
7-
import Footer from './footer';
8-
import IndexLinks from './index-links';
9-
import IndexSubNav from './index-sub-nav';
10-
import KatacodaPageEmbed from './katacoda-page-embed';
11-
import KatacodaPageLink from './katacoda-page-link';
12-
import KatacodaPanel from './katacoda-panel';
13-
import Layout from './layout';
14-
import LayoutContext from './layout-context';
15-
import LeftNav from './left-nav';
16-
import Link from './link';
17-
import Logo from './logo';
18-
import MainContent from './main-content';
19-
import PdfDownload from './pdf-download.js';
20-
import PrevNext from './prev-next';
21-
import SearchNavigationLinks from './search-navigation-links';
22-
import SearchNavigation from './search-navigation';
23-
import SideNavigation from './side-navigation';
24-
import StubCards from './stub-cards';
25-
import TableOfContents from './table-of-contents';
26-
import TextBalancer from './text-balancer';
27-
import TopBar from './top-bar';
28-
import TreeNode from './tree-node';
29-
import VersionDropdown from './version-dropdown';
1+
import Archive from "./archive";
2+
import BackButton from "./back-button";
3+
import CardDecks from "./card-decks";
4+
import CodeBlock from "./code-block";
5+
import DarkModeToggle from "./dark-mode-toggle";
6+
import DevOnly from "./dev-only";
7+
import DevFrontmatter from "./dev-frontmatter";
8+
import Footer from "./footer";
9+
import IndexLinks from "./index-links";
10+
import IndexSubNav from "./index-sub-nav";
11+
import KatacodaPageEmbed from "./katacoda-page-embed";
12+
import KatacodaPageLink from "./katacoda-page-link";
13+
import KatacodaPanel from "./katacoda-panel";
14+
import Layout from "./layout";
15+
import LayoutContext from "./layout-context";
16+
import LeftNav from "./left-nav";
17+
import Link from "./link";
18+
import Logo from "./logo";
19+
import MainContent from "./main-content";
20+
import PdfDownload from "./pdf-download.js";
21+
import PrevNext from "./prev-next";
22+
import SearchNavigationLinks from "./search-navigation-links";
23+
import SearchNavigation from "./search-navigation";
24+
import SideNavigation from "./side-navigation";
25+
import StubCards from "./stub-cards";
26+
import TableOfContents from "./table-of-contents";
27+
import TextBalancer from "./text-balancer";
28+
import TopBar from "./top-bar";
29+
import TreeNode from "./tree-node";
30+
import VersionDropdown from "./version-dropdown";
3031

3132
export {
33+
Archive,
3234
BackButton,
3335
CardDecks,
3436
CodeBlock,

0 commit comments

Comments
 (0)