Skip to content

Commit 7c1c9f4

Browse files
authoredJun 1, 2021
Fix "In this article" section (#3744)
1 parent 7b27488 commit 7c1c9f4

File tree

10 files changed

+261
-213
lines changed

10 files changed

+261
-213
lines changed
 

‎website/gatsby-config.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,23 @@ module.exports = {
6060
backgroundColor: "transparent",
6161
},
6262
},
63+
{
64+
resolve: `gatsby-remark-autolink-headers`,
65+
options: {
66+
icon: `<svg
67+
xmlns="http://www.w3.org/2000/svg"
68+
viewBox="0 0 512 512"
69+
width="16"
70+
height="16"
71+
>
72+
<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" />
73+
</svg>`,
74+
},
75+
},
6376
// todo: enable and fix
6477
// note: disabled for now, because # hash links are not recognized.
6578
// we probably need this plugin again gatsby-remark-autolink-headers.
66-
//`gatsby-remark-check-links`,
79+
// `gatsby-remark-check-links`,
6780
],
6881
},
6982
},

‎website/gatsby-node.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { createFilePath } = require("gatsby-source-filesystem");
22
const path = require("path");
33
const git = require("simple-git/promise");
4-
const moment = require("moment");
54

65
exports.createPages = async ({ actions, graphql, reporter }) => {
76
const { createPage, createRedirect } = actions;
@@ -129,34 +128,40 @@ exports.onCreateNode = async ({ node, actions, getNode }) => {
129128
value: filepath,
130129
});
131130

132-
let authorName;
133-
let lastUpdated;
131+
let authorName = "Unknown";
132+
let lastUpdated = "0000-00-00";
134133

135134
// we only run "git log" when building the production bundle
136135
// for development purposes we fallback to dummy values
137136
if (process.env.NODE_ENV === "production") {
138137
try {
139138
const result = await getGitLog(node.fileAbsolutePath);
140-
const data = result?.latest;
141-
const date = data?.date;
139+
const data = result.latest;
142140

143-
authorName = data?.authorName;
141+
if (data.authorName) {
142+
authorName = data.authorName;
143+
}
144144

145-
if (date) {
146-
lastUpdated = moment(date, "YYYY-MM-DD HH:mm:ss Z");
145+
if (data.date) {
146+
lastUpdated = data.date;
147147
}
148-
} catch {}
148+
} catch (error) {
149+
console.error(
150+
`Could not retrieve git information for ${node.fileAbsolutePath}`,
151+
error
152+
);
153+
}
149154
}
150155

151156
createNodeField({
152157
node,
153158
name: `lastAuthorName`,
154-
value: authorName ?? "Unknown",
159+
value: authorName,
155160
});
156161
createNodeField({
157162
node,
158163
name: `lastUpdated`,
159-
value: lastUpdated?.format("YYYY-MM-DD") ?? "0000-00-00",
164+
value: lastUpdated,
160165
});
161166
};
162167

@@ -233,7 +238,7 @@ function getGitLog(filepath) {
233238
file: filepath,
234239
n: 1,
235240
format: {
236-
date: `%ai`,
241+
date: `%cs`,
237242
authorName: `%an`,
238243
},
239244
};

‎website/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"gatsby-plugin-styled-components": "^3.10.0",
4444
"gatsby-plugin-ts": "^2.2.3",
4545
"gatsby-plugin-web-font-loader": "^1.0.4",
46+
"gatsby-remark-autolink-headers": "^4.3.0",
4647
"gatsby-remark-check-links": "^2.1.0",
4748
"gatsby-remark-images": "^3.11.0",
4849
"gatsby-remark-mermaid": "^2.1.0",
@@ -73,6 +74,7 @@
7374
"@storybook/addon-links": "^6.1.15",
7475
"@storybook/react": "^6.1.15",
7576
"@types/algoliasearch": "^3.34.10",
77+
"@types/github-slugger": "^1.3.0",
7678
"@types/prismjs": "^1.16.2",
7779
"@types/react": "^17.0.1",
7880
"@types/react-dom": "^17.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.