Skip to content

Commit dce75a2

Browse files
authored
Merge pull request #341 from carbonplan/Shane98c/supplement-cite
Add Cite, Sidenote, and Endnote support to supplements
2 parents f2d99f4 + d8dd059 commit dce75a2

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@carbonplan/components": "^13.2.1",
3030
"@carbonplan/emoji": "^2.0.0",
3131
"@carbonplan/icons": "^2.0.0",
32-
"@carbonplan/layouts": "^5.1.0",
32+
"@carbonplan/layouts": "^5.2.0",
3333
"@carbonplan/minimaps": "^2.6.0",
3434
"@carbonplan/seaweed-farming-model": "^1.0.0",
3535
"@carbonplan/theme": "^8.1.0",

pages/research/[id].page.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const SUPPLEMENT_COMPONENTS = {
5353
blockquote: Blockquote,
5454
Box,
5555
Link,
56+
Cite,
57+
Endnote,
58+
Sidenote,
5659
}
5760

5861
const Page = ({ id, type, source, frontMatter, references }) => {
@@ -106,7 +109,11 @@ const Page = ({ id, type, source, frontMatter, references }) => {
106109
)
107110
case 'supplement':
108111
return (
109-
<Supplement meta={frontMatter} back={frontMatter.back}>
112+
<Supplement
113+
meta={frontMatter}
114+
back={frontMatter.back}
115+
references={references}
116+
>
110117
<MDXRemote
111118
{...source}
112119
components={{
@@ -166,6 +173,7 @@ export const getStaticProps = async ({ params }) => {
166173
source: mdxSource,
167174
frontMatter: {
168175
...rest,
176+
color: rest.color ?? metadata.color,
169177
path: `/research/${params.id}`,
170178
number: metadata.number ?? 0,
171179
},

utils/generate-metadata.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,30 @@ const supplementMetadata = glob
5757
? 'articles'
5858
: 'commentary'
5959
const directory = path.join(process.cwd(), folder)
60+
61+
// Load parent article's frontmatter for color fallback
62+
const parentSource = fs.readFileSync(path.join(directory, `${id}/index.md`))
63+
const { data: parentData } = matter(parentSource)
64+
65+
// Load references from parent article
66+
let references
67+
try {
68+
references = fs.readFileSync(
69+
path.join(directory, `${id}/references.json`)
70+
)
71+
references = JSON.parse(references)
72+
} catch {
73+
references = {}
74+
}
75+
6076
return {
6177
...data,
78+
color: data.color ?? parentData.color,
6279
parentId: id,
6380
folder: folder,
6481
id: data.slug ?? `${id}-${fileName}`,
6582
path: `${directory}/${id}/${fileName}.md`,
83+
references,
6684
}
6785
})
6886

0 commit comments

Comments
 (0)