Skip to content

Commit

Permalink
Fix "In this article" section (#3744)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler authored Jun 1, 2021
1 parent 7b27488 commit 7c1c9f4
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 213 deletions.
15 changes: 14 additions & 1 deletion website/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ module.exports = {
backgroundColor: "transparent",
},
},
{
resolve: `gatsby-remark-autolink-headers`,
options: {
icon: `<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
width="16"
height="16"
>
<path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z" />
</svg>`,
},
},
// todo: enable and fix
// note: disabled for now, because # hash links are not recognized.
// we probably need this plugin again gatsby-remark-autolink-headers.
//`gatsby-remark-check-links`,
// `gatsby-remark-check-links`,
],
},
},
Expand Down
29 changes: 17 additions & 12 deletions website/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { createFilePath } = require("gatsby-source-filesystem");
const path = require("path");
const git = require("simple-git/promise");
const moment = require("moment");

exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage, createRedirect } = actions;
Expand Down Expand Up @@ -129,34 +128,40 @@ exports.onCreateNode = async ({ node, actions, getNode }) => {
value: filepath,
});

let authorName;
let lastUpdated;
let authorName = "Unknown";
let lastUpdated = "0000-00-00";

// we only run "git log" when building the production bundle
// for development purposes we fallback to dummy values
if (process.env.NODE_ENV === "production") {
try {
const result = await getGitLog(node.fileAbsolutePath);
const data = result?.latest;
const date = data?.date;
const data = result.latest;

authorName = data?.authorName;
if (data.authorName) {
authorName = data.authorName;
}

if (date) {
lastUpdated = moment(date, "YYYY-MM-DD HH:mm:ss Z");
if (data.date) {
lastUpdated = data.date;
}
} catch {}
} catch (error) {
console.error(
`Could not retrieve git information for ${node.fileAbsolutePath}`,
error
);
}
}

createNodeField({
node,
name: `lastAuthorName`,
value: authorName ?? "Unknown",
value: authorName,
});
createNodeField({
node,
name: `lastUpdated`,
value: lastUpdated?.format("YYYY-MM-DD") ?? "0000-00-00",
value: lastUpdated,
});
};

Expand Down Expand Up @@ -233,7 +238,7 @@ function getGitLog(filepath) {
file: filepath,
n: 1,
format: {
date: `%ai`,
date: `%cs`,
authorName: `%an`,
},
};
Expand Down
2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"gatsby-plugin-styled-components": "^3.10.0",
"gatsby-plugin-ts": "^2.2.3",
"gatsby-plugin-web-font-loader": "^1.0.4",
"gatsby-remark-autolink-headers": "^4.3.0",
"gatsby-remark-check-links": "^2.1.0",
"gatsby-remark-images": "^3.11.0",
"gatsby-remark-mermaid": "^2.1.0",
Expand Down Expand Up @@ -73,6 +74,7 @@
"@storybook/addon-links": "^6.1.15",
"@storybook/react": "^6.1.15",
"@types/algoliasearch": "^3.34.10",
"@types/github-slugger": "^1.3.0",
"@types/prismjs": "^1.16.2",
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.0",
Expand Down
Loading

0 comments on commit 7c1c9f4

Please sign in to comment.