Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit b30000e

Browse files
committed
Installed lunr 🚀
1 parent b90f4e8 commit b30000e

5 files changed

Lines changed: 89 additions & 2 deletions

File tree

gatsby-config.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GatsbyConfig } from "gatsby";
2+
import { authorName } from "./src/logic/blog-authors";
23

34
require("dotenv").config();
45

@@ -223,6 +224,41 @@ const config: GatsbyConfig = {
223224
queries: require("./src/logic/algolia"),
224225
},
225226
},
227+
{
228+
resolve: `gatsby-plugin-lunr`,
229+
options: {
230+
languages: [
231+
{
232+
name: "en",
233+
filterNodes: (node: any) => !!node.frontmatter,
234+
},
235+
],
236+
fields: [
237+
{ name: "title", store: true, attributes: { boost: 20 } },
238+
{ name: "content", store: true },
239+
{ name: "slug", store: true },
240+
{ name: "description", store: true },
241+
{ name: "authors", store: true },
242+
],
243+
filterNodes: (node: any) => !!node.frontmatter,
244+
resolvers: {
245+
MarkdownRemark: {
246+
title: (node: any) => node.frontmatter.title,
247+
content: (node: any) => node.rawMarkdownBody,
248+
slug: (node: any) => node.fields.slug,
249+
description: (node: any) => node.frontmatter.description,
250+
authors: (node: any) =>
251+
node.frontmatter.authors.map((author: string) =>
252+
authorName(author),
253+
),
254+
},
255+
},
256+
filename: "search_index.json",
257+
fetchOptions: {
258+
credentials: "same-origin",
259+
},
260+
},
261+
},
226262
],
227263
};
228264

package-lock.json

Lines changed: 44 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"gatsby-plugin-google-gtag": "^5.14.0",
6464
"gatsby-plugin-image": "^3.14.0",
6565
"gatsby-plugin-loadable-components-ssr": "^4.3.2",
66+
"gatsby-plugin-lunr": "^1.5.2",
6667
"gatsby-plugin-manifest": "^5.14.0",
6768
"gatsby-plugin-offline": "^6.14.0",
6869
"gatsby-plugin-react-helmet": "^6.14.0",

src/components/design-system/molecules/post-authors.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { FC } from "react";
22
import { tracking } from "../../../logic/tracking";
3-
import { BlogAuthor, blogAuthors } from "../../../logic/blog-authors";
3+
import {
4+
authorName,
5+
BlogAuthor,
6+
blogAuthors,
7+
} from "../../../logic/blog-authors";
48
import { graphql, useStaticQuery } from "gatsby";
59
import styled from "styled-components";
610
import { ContainerFluid } from "../atoms/container-fluid";
@@ -78,7 +82,7 @@ export const PostAuthors: FC<PostAuthorsProps> = ({
7882
const blogAuthor: BlogAuthor = blogAuthors[author!];
7983
const blogAuthorImage = blogAuthorsImages.allFile.edges.find(
8084
(blogAuthorImage) =>
81-
blogAuthorImage.node.name === author!.split("_").join("-"),
85+
author && blogAuthorImage.node.name === authorName(author),
8286
)!.node!.childImageSharp!.gatsbyImageData!;
8387

8488
return (

src/logic/blog-authors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ export const blogAuthors: { [authorName: string]: BlogAuthor } = {
7171
image: "sam-campisi.jpg",
7272
},
7373
};
74+
75+
export const authorName = (author: string) => author!.split("_").join("-");

0 commit comments

Comments
 (0)