Skip to content

Commit 81ff3bd

Browse files
committed
fix: filter tag (move most data from slug into frontmatter)
1 parent c85b500 commit 81ff3bd

File tree

8 files changed

+48
-144
lines changed

8 files changed

+48
-144
lines changed

gatsby-theme-academic/src/components/PageFragments/HomePage/SelectedResearch.jsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ const SelectedResearch = () => {
2222
allMdx(
2323
filter: {
2424
fileAbsolutePath: { regex: "/research\/.*\/index\\.md$/" }
25-
fields: {
26-
slug: {
27-
selected: { eq: true }
28-
}
25+
frontmatter: {
26+
selected: { eq: true }
2927
}
3028
}
3129
sort: { fields: [frontmatter___priority, frontmatter___title], order: ASC }
@@ -49,16 +47,12 @@ const SelectedResearch = () => {
4947
excerpt
5048
selected
5149
priority
52-
}
53-
fileAbsolutePath
54-
fields {
55-
slug {
56-
links {
57-
name
58-
url
59-
}
50+
links {
51+
name
52+
url
6053
}
6154
}
55+
fileAbsolutePath
6256
}
6357
}
6458
}

gatsby-theme-academic/src/components/Panel/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const Panel = (props) => {
3030
} else {
3131
nextSelectedTags.add(tagName);
3232
}
33-
// console.log('You are interested in: ', nextSelectedTags);
33+
console.log('You are interested in: ', nextSelectedTags);
3434
setSelectedTags(nextSelectedTags);
3535
};
3636

@@ -51,13 +51,13 @@ const Panel = (props) => {
5151

5252
if (data.allMdx) {
5353
data.allMdx.edges.forEach((val) => {
54-
if (!val.node || !val.node.fields || !val.node.fields.slug
55-
|| !val.node.fields.slug.tags) {
54+
console.log(val.node);
55+
if (!val.node || !val.node.frontmatter || !val.node.frontmatter.tags) {
5656
// eslint-disable-next-line no-param-reassign
5757
val.tags = new Set();
5858
} else {
5959
// eslint-disable-next-line no-param-reassign
60-
val.tags = new Set(val.node.fields.slug.tags);
60+
val.tags = new Set(val.node.frontmatter.tags);
6161
}
6262
});
6363
}

gatsby-theme-academic/src/components/ResearchCard/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import * as style from './researchCard.module.less';
1818
const ResearchCard = (props) => {
1919
const { data: { node }, tagsMap } = props;
2020
const {
21-
fields: { slug: { links } }, frontmatter: {
22-
title, authors, excerpt, path, date, tags, venue, cover,
21+
frontmatter: {
22+
title, authors, excerpt, path, date, tags, venue, cover, links,
2323
},
2424
} = node;
2525
const fluid = cover ? cover.childImageSharp.fluid : null;

gatsby-theme-academic/src/pages/index.jsx

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,17 @@ import Footer from '../components/PageLayout/Footer';
1010
import Header from '../components/PageLayout/Header';
1111
import SidebarWrapper from '../components/PageLayout/Sidebar';
1212

13-
export default ({ data }) => (
13+
export default () => (
1414
<Layout className="outerPadding">
1515
<Layout className="container">
1616
<Header />
1717
<SidebarWrapper>
1818
<AboutMe />
1919
<Experience />
2020
<Awards />
21-
<SelectedResearch data={data} />
21+
<SelectedResearch />
2222
<Footer />
2323
</SidebarWrapper>
2424
</Layout>
2525
</Layout>
2626
);
27-
28-
export const query = graphql`
29-
{
30-
allTag {
31-
edges {
32-
node {
33-
name
34-
color
35-
path
36-
}
37-
}
38-
}
39-
allMdx(
40-
filter: {
41-
fileAbsolutePath: { regex: "/research\/.*\/index\\.md$/" }
42-
fields: {
43-
slug: {
44-
selected: { eq: true }
45-
}
46-
}
47-
}
48-
sort: { fields: [frontmatter___priority, frontmatter___title], order: ASC }
49-
) {
50-
edges {
51-
node {
52-
frontmatter {
53-
cover {
54-
childImageSharp {
55-
fluid(maxWidth: 320, maxHeight: 180, fit: CONTAIN, background: "rgba(0,0,0,0)") {
56-
...GatsbyImageSharpFluid_tracedSVG
57-
}
58-
}
59-
}
60-
priority
61-
title
62-
}
63-
fileAbsolutePath
64-
fields {
65-
slug {
66-
date
67-
venue
68-
authors
69-
path
70-
title
71-
tags
72-
excerpt
73-
selected
74-
priority
75-
links {
76-
name
77-
url
78-
}
79-
}
80-
}
81-
}
82-
}
83-
}
84-
}
85-
`;

gatsby-theme-academic/src/pages/research/index.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,12 @@ export const query = graphql`
7777
tags
7878
excerpt
7979
priority
80-
}
81-
fileAbsolutePath
82-
fields {
83-
slug {
84-
links {
85-
name
86-
url
87-
}
80+
links {
81+
name
82+
url
8883
}
8984
}
85+
fileAbsolutePath
9086
}
9187
}
9288
}

gatsby-theme-academic/src/templates/post/post.jsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Layout, Empty, Row, Col, Input, Alert, Space
2+
Layout, Empty, Row, Col, Input, Alert, Space,
33
} from 'antd';
44
import { graphql } from 'gatsby';
55
import Img from 'gatsby-image';
@@ -28,10 +28,11 @@ import './highlight-syntax.less';
2828

2929
const Post = ({ data }) => {
3030
// console.log(data.mdx.tableOfContents);
31-
const { fields: { slug }, frontmatter: { cover }, tableOfContents } = data.mdx;
3231
const {
33-
title, excerpt, path, date, commit, html, nonce, htmlEncrypted, type,
34-
} = slug;
32+
fields: { slug: { html, nonce, htmlEncrypted } }, frontmatter: {
33+
cover, title, excerpt, path, date, commit, type,
34+
}, tableOfContents,
35+
} = data.mdx;
3536
const editTime = moment.unix(commit).format('MMM Do YYYY');
3637
const postTime = Utils.formatDate(date);
3738

@@ -171,21 +172,24 @@ export const pageQuery = graphql`
171172
}
172173
}
173174
}
175+
title
176+
date
177+
tags
178+
path
179+
excerpt
180+
links {
181+
name
182+
url
183+
}
184+
commit
185+
type
174186
}
175187
fileAbsolutePath
176188
fields {
177189
slug {
178190
html
179191
htmlEncrypted
180192
nonce
181-
title
182-
date
183-
tags
184-
path
185-
excerpt
186-
links { name }
187-
commit
188-
type
189193
}
190194
}
191195
}

gatsby-theme-academic/src/templates/tags/index.jsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const TagPage = ({
3131
// const tagImage = data.allFile.edges.find((edge) => edge.node.name === tag).node
3232
// .childImageSharp.fluid;
3333
const docs = data.allMdx.edges;
34-
const posts = _.filter(docs, (doc) => doc.node.fields.slug.type === 'posts');
35-
const research = _.filter(docs, (doc) => doc.node.fields.slug.type === 'research');
34+
const posts = _.filter(docs, (doc) => doc.node.frontmatter.type === 'posts');
35+
const research = _.filter(docs, (doc) => doc.node.frontmatter.type === 'research');
3636
const tags = data.allTag ? data.allTag.edges : [];
3737
const tagsMap = _.mapValues(_.keyBy(tags, (tag) => tag.node.name), 'node');
3838

@@ -146,7 +146,7 @@ export const pageQuery = graphql`
146146
}
147147
allMdx(
148148
filter: {
149-
fields: { slug: { tags: { in: [$tag] } } }
149+
frontmatter: { tags: { in: [$tag] } }
150150
fileAbsolutePath: { regex: "/index.md$/" }
151151
}
152152
sort: { fields: [frontmatter___date], order: DESC }
@@ -168,15 +168,11 @@ export const pageQuery = graphql`
168168
title
169169
tags
170170
excerpt
171-
}
172-
fields {
173-
slug {
174-
links {
171+
links {
175172
name
176173
url
177-
}
178-
type
179174
}
175+
type
180176
}
181177
}
182178
}

yarn.lock

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8637,13 +8637,6 @@ katex@^0.12.0:
86378637
dependencies:
86388638
commander "^2.19.0"
86398639

8640-
katex@^0.13.0:
8641-
version "0.13.24"
8642-
resolved "https://registry.yarnpkg.com/katex/-/katex-0.13.24.tgz#fe55455eb455698cb24b911a353d16a3c855d905"
8643-
integrity sha512-jZxYuKCma3VS5UuxOx/rFV1QyGSl3Uy/i0kTJF3HgQ5xMinCQVF8Zd4bMY/9aI9b9A2pjIBOsjSSm68ykTAr8w==
8644-
dependencies:
8645-
commander "^8.0.0"
8646-
86478640
katex@^0.15.2:
86488641
version "0.15.2"
86498642
resolved "https://registry.yarnpkg.com/katex/-/katex-0.15.2.tgz#c05ece41ab497597b17abca2cecde3e4c0127f9d"
@@ -9299,15 +9292,6 @@ mdast-util-gfm@^0.1.0:
92999292
mdast-util-gfm-task-list-item "^0.1.0"
93009293
mdast-util-to-markdown "^0.6.1"
93019294

9302-
mdast-util-math@^0.1.0:
9303-
version "0.1.2"
9304-
resolved "https://registry.yarnpkg.com/mdast-util-math/-/mdast-util-math-0.1.2.tgz#629a0793bd8822432917e5ddda5279492390cc2b"
9305-
integrity sha512-fogAitds+wH+QRas78Yr1TwmQGN4cW/G2WRw5ePuNoJbBSPJCxIOCE8MTzHgWHVSpgkRaPQTgfzXRE1CrwWSlg==
9306-
dependencies:
9307-
longest-streak "^2.0.0"
9308-
mdast-util-to-markdown "^0.6.0"
9309-
repeat-string "^1.0.0"
9310-
93119295
mdast-util-to-hast@10.0.1:
93129296
version "10.0.1"
93139297
resolved "https://registry.npm.taobao.org/mdast-util-to-hast/download/mdast-util-to-hast-10.0.1.tgz#0cfc82089494c52d46eb0e3edb7a4eb2aea021eb"
@@ -9576,14 +9560,6 @@ micromark-extension-gfm@^0.3.0:
95769560
micromark-extension-gfm-tagfilter "~0.3.0"
95779561
micromark-extension-gfm-task-list-item "~0.3.0"
95789562

9579-
micromark-extension-math@^0.1.0:
9580-
version "0.1.2"
9581-
resolved "https://registry.yarnpkg.com/micromark-extension-math/-/micromark-extension-math-0.1.2.tgz#5d7bb2b86018da4a758c05f3991664430ee4d711"
9582-
integrity sha512-ZJXsT2eVPM8VTmcw0CPSDeyonOn9SziGK3Z+nkf9Vb6xMPeU+4JMEnO6vzDL10562Favw8Vste74f54rxJ/i6Q==
9583-
dependencies:
9584-
katex "^0.12.0"
9585-
micromark "~2.11.0"
9586-
95879563
micromark@^2.11.3, micromark@~2.11.0, micromark@~2.11.3:
95889564
version "2.11.4"
95899565
resolved "https://registry.yarnpkg.com/micromark/-/micromark-2.11.4.tgz#d13436138eea826383e822449c9a5c50ee44665a"
@@ -12398,14 +12374,14 @@ regjsparser@^0.6.4:
1239812374
dependencies:
1239912375
jsesc "~0.5.0"
1240012376

12401-
rehype-katex@^5.0.0:
12402-
version "5.0.0"
12403-
resolved "https://registry.yarnpkg.com/rehype-katex/-/rehype-katex-5.0.0.tgz#b556f24fde918f28ba1cb642ea71c7e82f3373d7"
12404-
integrity sha512-ksSuEKCql/IiIadOHiKRMjypva9BLhuwQNascMqaoGLDVd0k2NlE2wMvgZ3rpItzRKCd6vs8s7MFbb8pcR0AEg==
12377+
rehype-katex@^4.0.0:
12378+
version "4.0.0"
12379+
resolved "https://registry.yarnpkg.com/rehype-katex/-/rehype-katex-4.0.0.tgz#ce11a5db0bff014350e7a9cfd30147d314b14330"
12380+
integrity sha512-0mgBqYugQyIW0eUl6RDOZ28Cat2YzrnWGaYgKCMQnJw6ClmKgLqXBnkDAPGh2mwxvkkKwQOUMUpSLpA5rt7rzA==
1240512381
dependencies:
1240612382
"@types/katex" "^0.11.0"
1240712383
hast-util-to-text "^2.0.0"
12408-
katex "^0.13.0"
12384+
katex "^0.12.0"
1240912385
rehype-parse "^7.0.0"
1241012386
unified "^9.0.0"
1241112387
unist-util-visit "^2.0.0"
@@ -12467,13 +12443,10 @@ remark-html@^13.0.1:
1246712443
hast-util-to-html "^7.0.0"
1246812444
mdast-util-to-hast "^10.0.0"
1246912445

12470-
remark-math@^4.0.0:
12471-
version "4.0.0"
12472-
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-4.0.0.tgz#494ddd50766555ad2332e3afca7796a76452256f"
12473-
integrity sha512-lH7SoQenXtQrvL0bm+mjZbvOk//YWNuyR+MxV18Qyv8rgFmMEGNuB0TSCQDkoDaiJ40FCnG8lxErc/zhcedYbw==
12474-
dependencies:
12475-
mdast-util-math "^0.1.0"
12476-
micromark-extension-math "^0.1.0"
12446+
remark-math@^3.0.1:
12447+
version "3.0.1"
12448+
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-3.0.1.tgz#85a02a15b15cad34b89a27244d4887b3a95185bb"
12449+
integrity sha512-epT77R/HK0x7NqrWHdSV75uNLwn8g9qTyMqCRCDujL0vj/6T6+yhdrR7mjELWtkse+Fw02kijAaBuVcHBor1+Q==
1247712450

1247812451
remark-mdx@1.6.22:
1247912452
version "1.6.22"

0 commit comments

Comments
 (0)