Skip to content

Commit

Permalink
fix: filter tag (move most data from slug into frontmatter)
Browse files Browse the repository at this point in the history
  • Loading branch information
tc-imba committed Feb 26, 2022
1 parent c85b500 commit 81ff3bd
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ const SelectedResearch = () => {
allMdx(
filter: {
fileAbsolutePath: { regex: "/research\/.*\/index\\.md$/" }
fields: {
slug: {
selected: { eq: true }
}
frontmatter: {
selected: { eq: true }
}
}
sort: { fields: [frontmatter___priority, frontmatter___title], order: ASC }
Expand All @@ -49,16 +47,12 @@ const SelectedResearch = () => {
excerpt
selected
priority
}
fileAbsolutePath
fields {
slug {
links {
name
url
}
links {
name
url
}
}
fileAbsolutePath
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions gatsby-theme-academic/src/components/Panel/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Panel = (props) => {
} else {
nextSelectedTags.add(tagName);
}
// console.log('You are interested in: ', nextSelectedTags);
console.log('You are interested in: ', nextSelectedTags);
setSelectedTags(nextSelectedTags);
};

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

if (data.allMdx) {
data.allMdx.edges.forEach((val) => {
if (!val.node || !val.node.fields || !val.node.fields.slug
|| !val.node.fields.slug.tags) {
console.log(val.node);
if (!val.node || !val.node.frontmatter || !val.node.frontmatter.tags) {
// eslint-disable-next-line no-param-reassign
val.tags = new Set();
} else {
// eslint-disable-next-line no-param-reassign
val.tags = new Set(val.node.fields.slug.tags);
val.tags = new Set(val.node.frontmatter.tags);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions gatsby-theme-academic/src/components/ResearchCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import * as style from './researchCard.module.less';
const ResearchCard = (props) => {
const { data: { node }, tagsMap } = props;
const {
fields: { slug: { links } }, frontmatter: {
title, authors, excerpt, path, date, tags, venue, cover,
frontmatter: {
title, authors, excerpt, path, date, tags, venue, cover, links,
},
} = node;
const fluid = cover ? cover.childImageSharp.fluid : null;
Expand Down
63 changes: 2 additions & 61 deletions gatsby-theme-academic/src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,17 @@ import Footer from '../components/PageLayout/Footer';
import Header from '../components/PageLayout/Header';
import SidebarWrapper from '../components/PageLayout/Sidebar';

export default ({ data }) => (
export default () => (
<Layout className="outerPadding">
<Layout className="container">
<Header />
<SidebarWrapper>
<AboutMe />
<Experience />
<Awards />
<SelectedResearch data={data} />
<SelectedResearch />
<Footer />
</SidebarWrapper>
</Layout>
</Layout>
);

export const query = graphql`
{
allTag {
edges {
node {
name
color
path
}
}
}
allMdx(
filter: {
fileAbsolutePath: { regex: "/research\/.*\/index\\.md$/" }
fields: {
slug: {
selected: { eq: true }
}
}
}
sort: { fields: [frontmatter___priority, frontmatter___title], order: ASC }
) {
edges {
node {
frontmatter {
cover {
childImageSharp {
fluid(maxWidth: 320, maxHeight: 180, fit: CONTAIN, background: "rgba(0,0,0,0)") {
...GatsbyImageSharpFluid_tracedSVG
}
}
}
priority
title
}
fileAbsolutePath
fields {
slug {
date
venue
authors
path
title
tags
excerpt
selected
priority
links {
name
url
}
}
}
}
}
}
}
`;
12 changes: 4 additions & 8 deletions gatsby-theme-academic/src/pages/research/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ export const query = graphql`
tags
excerpt
priority
}
fileAbsolutePath
fields {
slug {
links {
name
url
}
links {
name
url
}
}
fileAbsolutePath
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions gatsby-theme-academic/src/templates/post/post.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Layout, Empty, Row, Col, Input, Alert, Space
Layout, Empty, Row, Col, Input, Alert, Space,
} from 'antd';
import { graphql } from 'gatsby';
import Img from 'gatsby-image';
Expand Down Expand Up @@ -28,10 +28,11 @@ import './highlight-syntax.less';

const Post = ({ data }) => {
// console.log(data.mdx.tableOfContents);
const { fields: { slug }, frontmatter: { cover }, tableOfContents } = data.mdx;
const {
title, excerpt, path, date, commit, html, nonce, htmlEncrypted, type,
} = slug;
fields: { slug: { html, nonce, htmlEncrypted } }, frontmatter: {
cover, title, excerpt, path, date, commit, type,
}, tableOfContents,
} = data.mdx;
const editTime = moment.unix(commit).format('MMM Do YYYY');
const postTime = Utils.formatDate(date);

Expand Down Expand Up @@ -171,21 +172,24 @@ export const pageQuery = graphql`
}
}
}
title
date
tags
path
excerpt
links {
name
url
}
commit
type
}
fileAbsolutePath
fields {
slug {
html
htmlEncrypted
nonce
title
date
tags
path
excerpt
links { name }
commit
type
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions gatsby-theme-academic/src/templates/tags/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const TagPage = ({
// const tagImage = data.allFile.edges.find((edge) => edge.node.name === tag).node
// .childImageSharp.fluid;
const docs = data.allMdx.edges;
const posts = _.filter(docs, (doc) => doc.node.fields.slug.type === 'posts');
const research = _.filter(docs, (doc) => doc.node.fields.slug.type === 'research');
const posts = _.filter(docs, (doc) => doc.node.frontmatter.type === 'posts');
const research = _.filter(docs, (doc) => doc.node.frontmatter.type === 'research');
const tags = data.allTag ? data.allTag.edges : [];
const tagsMap = _.mapValues(_.keyBy(tags, (tag) => tag.node.name), 'node');

Expand Down Expand Up @@ -146,7 +146,7 @@ export const pageQuery = graphql`
}
allMdx(
filter: {
fields: { slug: { tags: { in: [$tag] } } }
frontmatter: { tags: { in: [$tag] } }
fileAbsolutePath: { regex: "/index.md$/" }
}
sort: { fields: [frontmatter___date], order: DESC }
Expand All @@ -168,15 +168,11 @@ export const pageQuery = graphql`
title
tags
excerpt
}
fields {
slug {
links {
links {
name
url
}
type
}
type
}
}
}
Expand Down
45 changes: 9 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8637,13 +8637,6 @@ katex@^0.12.0:
dependencies:
commander "^2.19.0"

katex@^0.13.0:
version "0.13.24"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.13.24.tgz#fe55455eb455698cb24b911a353d16a3c855d905"
integrity sha512-jZxYuKCma3VS5UuxOx/rFV1QyGSl3Uy/i0kTJF3HgQ5xMinCQVF8Zd4bMY/9aI9b9A2pjIBOsjSSm68ykTAr8w==
dependencies:
commander "^8.0.0"

katex@^0.15.2:
version "0.15.2"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.15.2.tgz#c05ece41ab497597b17abca2cecde3e4c0127f9d"
Expand Down Expand Up @@ -9299,15 +9292,6 @@ mdast-util-gfm@^0.1.0:
mdast-util-gfm-task-list-item "^0.1.0"
mdast-util-to-markdown "^0.6.1"

mdast-util-math@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/mdast-util-math/-/mdast-util-math-0.1.2.tgz#629a0793bd8822432917e5ddda5279492390cc2b"
integrity sha512-fogAitds+wH+QRas78Yr1TwmQGN4cW/G2WRw5ePuNoJbBSPJCxIOCE8MTzHgWHVSpgkRaPQTgfzXRE1CrwWSlg==
dependencies:
longest-streak "^2.0.0"
mdast-util-to-markdown "^0.6.0"
repeat-string "^1.0.0"

mdast-util-to-hast@10.0.1:
version "10.0.1"
resolved "https://registry.npm.taobao.org/mdast-util-to-hast/download/mdast-util-to-hast-10.0.1.tgz#0cfc82089494c52d46eb0e3edb7a4eb2aea021eb"
Expand Down Expand Up @@ -9576,14 +9560,6 @@ micromark-extension-gfm@^0.3.0:
micromark-extension-gfm-tagfilter "~0.3.0"
micromark-extension-gfm-task-list-item "~0.3.0"

micromark-extension-math@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/micromark-extension-math/-/micromark-extension-math-0.1.2.tgz#5d7bb2b86018da4a758c05f3991664430ee4d711"
integrity sha512-ZJXsT2eVPM8VTmcw0CPSDeyonOn9SziGK3Z+nkf9Vb6xMPeU+4JMEnO6vzDL10562Favw8Vste74f54rxJ/i6Q==
dependencies:
katex "^0.12.0"
micromark "~2.11.0"

micromark@^2.11.3, micromark@~2.11.0, micromark@~2.11.3:
version "2.11.4"
resolved "https://registry.yarnpkg.com/micromark/-/micromark-2.11.4.tgz#d13436138eea826383e822449c9a5c50ee44665a"
Expand Down Expand Up @@ -12398,14 +12374,14 @@ regjsparser@^0.6.4:
dependencies:
jsesc "~0.5.0"

rehype-katex@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/rehype-katex/-/rehype-katex-5.0.0.tgz#b556f24fde918f28ba1cb642ea71c7e82f3373d7"
integrity sha512-ksSuEKCql/IiIadOHiKRMjypva9BLhuwQNascMqaoGLDVd0k2NlE2wMvgZ3rpItzRKCd6vs8s7MFbb8pcR0AEg==
rehype-katex@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/rehype-katex/-/rehype-katex-4.0.0.tgz#ce11a5db0bff014350e7a9cfd30147d314b14330"
integrity sha512-0mgBqYugQyIW0eUl6RDOZ28Cat2YzrnWGaYgKCMQnJw6ClmKgLqXBnkDAPGh2mwxvkkKwQOUMUpSLpA5rt7rzA==
dependencies:
"@types/katex" "^0.11.0"
hast-util-to-text "^2.0.0"
katex "^0.13.0"
katex "^0.12.0"
rehype-parse "^7.0.0"
unified "^9.0.0"
unist-util-visit "^2.0.0"
Expand Down Expand Up @@ -12467,13 +12443,10 @@ remark-html@^13.0.1:
hast-util-to-html "^7.0.0"
mdast-util-to-hast "^10.0.0"

remark-math@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-4.0.0.tgz#494ddd50766555ad2332e3afca7796a76452256f"
integrity sha512-lH7SoQenXtQrvL0bm+mjZbvOk//YWNuyR+MxV18Qyv8rgFmMEGNuB0TSCQDkoDaiJ40FCnG8lxErc/zhcedYbw==
dependencies:
mdast-util-math "^0.1.0"
micromark-extension-math "^0.1.0"
remark-math@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-3.0.1.tgz#85a02a15b15cad34b89a27244d4887b3a95185bb"
integrity sha512-epT77R/HK0x7NqrWHdSV75uNLwn8g9qTyMqCRCDujL0vj/6T6+yhdrR7mjELWtkse+Fw02kijAaBuVcHBor1+Q==

remark-mdx@1.6.22:
version "1.6.22"
Expand Down

0 comments on commit 81ff3bd

Please sign in to comment.