Skip to content

Commit

Permalink
add archive component
Browse files Browse the repository at this point in the history
Former-commit-id: b6184cb
  • Loading branch information
frago12 committed Jul 13, 2021
1 parent e8f5522 commit 236e249
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 88 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ We recommend using MacOS to work with the EDB Docs application.

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

1. Create a `.env` file: `cp env .env.development`.

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.

- If you already have Node installed, you can verify your version by running `node -v` in the cloned repo directory.
Expand Down
1 change: 1 addition & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GATSBY_ENVIRONMENT_BRANCH=develop
100 changes: 53 additions & 47 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// this patch is required to consistently load all the doc files
const realFs = require('fs');
const gracefulFs = require('graceful-fs');
const realFs = require("fs");
const path = require("path");
const gracefulFs = require("graceful-fs");
gracefulFs.gracefulify(realFs);

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

const {
replacePathVersion,
Expand All @@ -23,16 +24,16 @@ const {
configureLegacyRedirects,
readFile,
writeFile,
} = require('./src/constants/gatsby-utils.js');
} = require("./src/constants/gatsby-utils.js");

const isBuild = process.env.NODE_ENV === 'production';
const isProduction = process.env.APP_ENV === 'production';
const isBuild = process.env.NODE_ENV === "production";
const isProduction = process.env.APP_ENV === "production";

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

if (node.internal.mediaType === 'text/yaml') loadNodeContent(node);
if (node.internal.type !== 'Mdx') return;
if (node.internal.mediaType === "text/yaml") loadNodeContent(node);
if (node.internal.type !== "Mdx") return;

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

let relativeFilePath = createFilePath({ node, getNode });
if (nodeFields.docType === 'doc') {
if (nodeFields.docType === "doc") {
relativeFilePath = `/${fileNode.sourceInstanceName}${relativeFilePath}`;
}

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

if (nodeFields.docType === 'doc') {
if (nodeFields.docType === "doc") {
Object.assign(nodeFields, {
product: relativeFilePath.split('/')[1],
version: relativeFilePath.split('/')[2],
topic: 'null',
product: relativeFilePath.split("/")[1],
version: relativeFilePath.split("/")[2],
topic: "null",
});
} else if (nodeFields.docType === 'advocacy') {
} else if (nodeFields.docType === "advocacy") {
Object.assign(nodeFields, {
product: 'null',
version: '0',
topic: relativeFilePath.split('/')[2],
product: "null",
version: "0",
topic: relativeFilePath.split("/")[2],
});
}

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

if (result.errors) {
reporter.panic('createPages graphql query has errors!', result.errors);
reporter.panic("createPages graphql query has errors!", result.errors);
}

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

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

// perform depth first preorder traversal
const treeRoot = mdxNodesToTree(nodes);
Expand All @@ -155,17 +156,17 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
const addedChildPaths = {};
curr.navigationNodes = [];
(curr.mdxNode?.frontmatter?.navigation || []).forEach((navEntry) => {
if (navEntry.startsWith('#')) {
if (navEntry.startsWith("#")) {
curr.navigationNodes.push({
path: null,
title: navEntry.replace('#', '').trim(),
title: navEntry.replace("#", "").trim(),
});
return;
}

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

const { docType } = node.fields;
if (docType === 'doc') {
if (docType === "doc") {
createDoc(navTree, prevNext, node, productVersions, actions);
} else if (docType === 'advocacy') {
} else if (docType === "advocacy") {
createAdvocacy(navTree, prevNext, node, learn, actions);
}
}
Expand Down Expand Up @@ -237,18 +238,18 @@ const createDoc = (navTree, prevNext, doc, productVersions, actions) => {
}

const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath);
const docsRepoUrl = 'https://github.com/EnterpriseDB/docs';
const branch = isProduction ? 'main' : 'develop';
const docsRepoUrl = "https://github.com/EnterpriseDB/docs";
const branch = isProduction ? "main" : "develop";
const fileUrlSegment =
removeTrailingSlash(doc.fields.path) +
(isIndexPage ? '/index.mdx' : '.mdx');
(isIndexPage ? "/index.mdx" : ".mdx");
const githubFileLink = `${docsRepoUrl}/commits/${branch}/product_docs/docs${fileUrlSegment}`;
const githubEditLink = `${docsRepoUrl}/edit/${branch}/product_docs/docs${fileUrlSegment}`;
const githubIssuesLink = `${docsRepoUrl}/issues/new?title=Feedback%20on%20${encodeURIComponent(
fileUrlSegment,
)}`;

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

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

const advocacyDocsRepoUrl = 'https://github.com/EnterpriseDB/docs';
const branch = isProduction ? 'main' : 'develop';
const advocacyDocsRepoUrl = "https://github.com/EnterpriseDB/docs";
const branch = isProduction ? "main" : "develop";
const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath);
const fileUrlSegment =
removeTrailingSlash(doc.fields.path) +
(isIndexPage ? '/index.mdx' : '.mdx');
(isIndexPage ? "/index.mdx" : ".mdx");
const githubFileLink = `${advocacyDocsRepoUrl}/commits/${branch}/advocacy_docs${fileUrlSegment}`;
const githubEditLink = `${advocacyDocsRepoUrl}/edit/${branch}/advocacy_docs${fileUrlSegment}`;
const githubIssuesLink = `${advocacyDocsRepoUrl}/issues/new?title=Regarding%20${encodeURIComponent(
Expand All @@ -311,13 +312,13 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
// workaround for https://github.com/gatsbyjs/gatsby/issues/26520
actions.createPage({
path: doc.fields.path,
component: require.resolve('./src/templates/learn-doc.js'),
component: require.resolve("./src/templates/learn-doc.js"),
context: {},
});

actions.createPage({
path: doc.fields.path,
component: require.resolve('./src/templates/learn-doc.js'),
component: require.resolve("./src/templates/learn-doc.js"),
context: {
nodeId: doc.id,
frontmatter: doc.frontmatter,
Expand All @@ -342,7 +343,7 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
const path = `${doc.fields.path}${katacodaPage.scenario}`;
actions.createPage({
path: path,
component: require.resolve('./src/templates/katacoda-page.js'),
component: require.resolve("./src/templates/katacoda-page.js"),
context: {
...katacodaPage,
pagePath: path,
Expand All @@ -359,7 +360,7 @@ const processFileNodes = (fileNodes, actions) => {
fileNodes.forEach((node) => {
actions.createPage({
path: node.relativePath,
component: require.resolve('./src/templates/file.js'),
component: require.resolve("./src/templates/file.js"),
context: {
nodeId: node.id,
},
Expand All @@ -375,13 +376,13 @@ exports.sourceNodes = async ({
// create edb-git node
const sha = (
await new Promise((resolve, reject) => {
exec('git rev-parse HEAD', (error, stdout, stderr) => resolve(stdout));
exec("git rev-parse HEAD", (error, stdout, stderr) => resolve(stdout));
})
).trim();

const branch = (
await new Promise((resolve, reject) => {
exec('git branch --show-current', (error, stdout, stderr) =>
exec("git branch --show-current", (error, stdout, stderr) =>
resolve(stdout),
);
})
Expand All @@ -390,9 +391,9 @@ exports.sourceNodes = async ({
const gitData = { sha, branch };
createNode({
...gitData,
id: createNodeId('edb-git'),
id: createNodeId("edb-git"),
internal: {
type: 'edbGit',
type: "edbGit",
contentDigest: createContentDigest(gitData),
},
});
Expand Down Expand Up @@ -424,29 +425,34 @@ exports.createSchemaCustomization = ({ actions }) => {

exports.onPreBootstrap = () => {
console.log(`
_____ ____ _____ ____
| __|| \\ | __ | | \\ ___ ___ ___
_____ ____ _____ ____
| __|| \\ | __ | | \\ ___ ___ ___
| __|| | || __ -| | | || . || _||_ -|
|_____||____/ |_____| |____/ |___||___||___|
`);
};

exports.onPostBuild = async ({ reporter, pathPrefix }) => {
const originalRedirects = await readFile('public/_redirects');
realFs.copyFileSync(
path.join(__dirname, "/netlify.toml"),
path.join(__dirname, "/public/netlify.toml"),
);

const originalRedirects = await readFile("public/_redirects");

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

if (filteredRedirects.length === originalRedirects.length) {
reporter.warn('no redirects were filtered out, did something change?');
reporter.warn("no redirects were filtered out, did something change?");
}

await writeFile(
'public/_redirects',
"public/_redirects",
`${filteredRedirects}\n\n# Netlify pathPrefix path rewrite\n${pathPrefix}/* /:splat 200`,
);
};
8 changes: 8 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[context.production]
GATSBY_ENVIRONMENT_BRANCH = "main"

[context.deploy-preview.environment]
GATSBY_ENVIRONMENT_BRANCH = "develop"

[context.branch-deploy]
GATSBY_ENVIRONMENT_BRANCH = "develop"
26 changes: 26 additions & 0 deletions src/components/archive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";

import Icon from "./icon";
import Link from "./link";

const environment = process.env.GATSBY_ENVIRONMENT_BRANCH;

export default function Archive({ title, path = "", ...props }) {
const updatedPath = !path.startsWith('/') ? `/${path}` : path
const url = `https://github.com/EnterpriseDB/docs-archive/raw/${environment}${updatedPath}`;

return (
<Link to={url} title={title} className="w-100 d-block" {...props}>
<PdfIcon /> {title}
</Link>
);
}

const PdfIcon = () => (
<Icon
iconName="PDF"
className="fill-orange position-relative top-minus-1"
width="16"
height="auto"
/>
);
60 changes: 31 additions & 29 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import BackButton from './back-button';
import CardDecks from './card-decks';
import CodeBlock from './code-block';
import DarkModeToggle from './dark-mode-toggle';
import DevOnly from './dev-only';
import DevFrontmatter from './dev-frontmatter';
import Footer from './footer';
import IndexLinks from './index-links';
import IndexSubNav from './index-sub-nav';
import KatacodaPageEmbed from './katacoda-page-embed';
import KatacodaPageLink from './katacoda-page-link';
import KatacodaPanel from './katacoda-panel';
import Layout from './layout';
import LayoutContext from './layout-context';
import LeftNav from './left-nav';
import Link from './link';
import Logo from './logo';
import MainContent from './main-content';
import PdfDownload from './pdf-download.js';
import PrevNext from './prev-next';
import SearchNavigationLinks from './search-navigation-links';
import SearchNavigation from './search-navigation';
import SideNavigation from './side-navigation';
import StubCards from './stub-cards';
import TableOfContents from './table-of-contents';
import TextBalancer from './text-balancer';
import TopBar from './top-bar';
import TreeNode from './tree-node';
import VersionDropdown from './version-dropdown';
import Archive from "./archive";
import BackButton from "./back-button";
import CardDecks from "./card-decks";
import CodeBlock from "./code-block";
import DarkModeToggle from "./dark-mode-toggle";
import DevOnly from "./dev-only";
import DevFrontmatter from "./dev-frontmatter";
import Footer from "./footer";
import IndexLinks from "./index-links";
import IndexSubNav from "./index-sub-nav";
import KatacodaPageEmbed from "./katacoda-page-embed";
import KatacodaPageLink from "./katacoda-page-link";
import KatacodaPanel from "./katacoda-panel";
import Layout from "./layout";
import LayoutContext from "./layout-context";
import LeftNav from "./left-nav";
import Link from "./link";
import Logo from "./logo";
import MainContent from "./main-content";
import PdfDownload from "./pdf-download.js";
import PrevNext from "./prev-next";
import SearchNavigationLinks from "./search-navigation-links";
import SearchNavigation from "./search-navigation";
import SideNavigation from "./side-navigation";
import StubCards from "./stub-cards";
import TableOfContents from "./table-of-contents";
import TextBalancer from "./text-balancer";
import TopBar from "./top-bar";
import TreeNode from "./tree-node";
import VersionDropdown from "./version-dropdown";

export {
Archive,
BackButton,
CardDecks,
CodeBlock,
Expand Down
Loading

0 comments on commit 236e249

Please sign in to comment.