Skip to content

Commit d65cb59

Browse files
committed
Create Gatsby configuration files
1 parent b1eaee3 commit d65cb59

File tree

3 files changed

+310
-0
lines changed

3 files changed

+310
-0
lines changed

gatsby-browser.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Import fonts to expose them globaly
3+
*/
4+
import 'typeface-fira-code';
5+
6+
import React from 'react';
7+
import RootWrapper from './src/context/ThemeProvider';
8+
9+
export const wrapRootElement = ({ element }, pluginOptions) => {
10+
return <RootWrapper>{element}</RootWrapper>;
11+
};

gatsby-config.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
var path = require("path");
2+
3+
module.exports = {
4+
siteMetadata: {
5+
pathPrefix: '/',
6+
keywords: [
7+
'Anit Shrestha Manandhar',
8+
'codeanit',
9+
'Software Engineering',
10+
'Technical Articles',
11+
'Programming Blog',
12+
],
13+
title: "Technical Blog by Anit Shrestha Manandhar.",
14+
titleAlt: 'codeanit.com',
15+
description:
16+
"I am not an expert, I code for a living. I have some experience building software systems that solves the problems. Interested in mind, body and technology. Here are few things I learn and share my view about tech.",
17+
url: 'https://codeanit.com', // Site domain without trailing slash
18+
siteUrl: 'https://codeanit.com/', // url + pathPrefix
19+
siteLanguage: 'en', // Language Tag on <html> element
20+
logo: 'src/static/logo/logo.png',
21+
// banner: 'src/static/logo/banner.png',
22+
favicon: 'static/favicon.png', // Manifest favicon generation
23+
shortName: 'codeanit', // Shortname for manifest, must be shorter than 12 characters
24+
author: 'codeanit', // Author for schemaORGJSONLD
25+
themeColor: '#000000',
26+
backgroundColor: '#ffffff',
27+
twitter: '@codeanit', // Twitter Username
28+
twitterDesc:
29+
'Tweets by Anit Shrestha Manandhar.',
30+
},
31+
plugins: [
32+
'gatsby-plugin-printer',
33+
{
34+
resolve: 'gatsby-plugin-lunr',
35+
options: {
36+
languages: [{ name: 'en' }],
37+
fields: [
38+
{ name: 'title', store: true, attributes: { boost: 20 } },
39+
{ name: 'subtitle', store: true, attributes: { boost: 5 } },
40+
{ name: 'content' },
41+
{ name: 'slug', store: true },
42+
{ name: 'date', store: true },
43+
{ name: 'keywords', store: true },
44+
],
45+
resolvers: {
46+
Mdx: {
47+
title: node => node.frontmatter.title,
48+
subtitle: node => node.frontmatter.subtitle,
49+
content: node => node.rawBody,
50+
date: node => node.frontmatter.date,
51+
slug: node => `/posts/${node.frontmatter.slug}`,
52+
keywords: node => node.formatter.keywords,
53+
},
54+
},
55+
filename: 'search_index.json',
56+
},
57+
},
58+
{
59+
resolve: `gatsby-source-filesystem`,
60+
options: {
61+
name: `posts`,
62+
path: `${__dirname}/content/`,
63+
},
64+
},
65+
{
66+
resolve: `gatsby-plugin-manifest`,
67+
options: {
68+
name: `Technical Blog by Anit Shrestha Manandhar.`,
69+
short_name: `blog by codeanit`,
70+
start_url: `/`,
71+
background_color: `#ffffff`,
72+
theme_color: `#ffffff`,
73+
display: `minimal-ui`,
74+
icon: `static/icon.png`, // This path is relative to the root of the site.
75+
},
76+
},
77+
{
78+
resolve: `gatsby-plugin-google-analytics`,
79+
options: {
80+
trackingId: 'GTM-KWW9X8N',
81+
head: true,
82+
},
83+
},
84+
{
85+
resolve: 'gatsby-plugin-sitemap',
86+
options: {
87+
query: `
88+
{
89+
site {
90+
siteMetadata {
91+
siteUrl
92+
}
93+
}
94+
allSitePage {
95+
edges {
96+
node {
97+
path
98+
}
99+
}
100+
}
101+
}
102+
`,
103+
serialize: ({ site, allSitePage }) =>
104+
allSitePage.edges.map(edge => {
105+
return {
106+
url: `${site.siteMetadata.siteUrl}${
107+
edge.node.path === '/' ? '' : edge.node.path
108+
}/`,
109+
changefreq: `daily`,
110+
priority: 0.7,
111+
};
112+
}),
113+
},
114+
},
115+
'gatsby-plugin-offline',
116+
'gatsby-plugin-typescript',
117+
{
118+
resolve: 'gatsby-plugin-mdx',
119+
options: {
120+
extensions: ['.mdx', '.md'],
121+
defaultLayouts: {
122+
default: require.resolve('./src/templates/Blog.tsx'),
123+
posts: require.resolve('./src/templates/Blog.tsx')
124+
},
125+
remarkPlugins: [require('remark-toc')],
126+
gatsbyRemarkPlugins: [
127+
{
128+
resolve: 'gatsby-remark-images',
129+
options: {
130+
maxWidth: 900,
131+
backgroundColor: 'transparent',
132+
showCaptions: true,
133+
},
134+
},
135+
'gatsby-remark-copy-linked-files',
136+
'gatsby-remark-sectionize',
137+
{
138+
resolve: 'gatsby-remark-autolink-headers',
139+
options: {
140+
icon: `<svg style="width: 0px; height: 0px;"></svg>`,
141+
},
142+
},
143+
],
144+
},
145+
},
146+
'gatsby-transformer-sharp',
147+
'gatsby-plugin-sharp',
148+
{
149+
resolve: 'gatsby-plugin-typography',
150+
options: {
151+
pathToConfigModule: './src/utils/typography',
152+
},
153+
},
154+
{
155+
resolve: `gatsby-plugin-page-creator`,
156+
options: {
157+
path: path.resolve(__dirname, `src/pages`),
158+
},
159+
},
160+
'gatsby-plugin-emotion',
161+
'gatsby-plugin-react-helmet',
162+
'gatsby-plugin-twitter',
163+
164+
],
165+
};

gatsby-node.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
const path = require('path');
2+
const slugify = require('@sindresorhus/slugify');
3+
const { runScreenshots } = require('gatsby-plugin-printer');
4+
5+
exports.createPages = ({ graphql, actions }) => {
6+
const { createPage } = actions;
7+
return new Promise((resolve, reject) => {
8+
resolve(
9+
graphql(
10+
`
11+
{
12+
allMdx {
13+
edges {
14+
node {
15+
id
16+
tableOfContents
17+
timeToRead
18+
frontmatter {
19+
slug
20+
title
21+
subtitle
22+
date
23+
type
24+
cover {
25+
childImageSharp {
26+
fluid(
27+
maxWidth: 1500
28+
maxHeight: 700
29+
quality: 100
30+
cropFocus: ENTROPY
31+
) {
32+
base64
33+
tracedSVG
34+
aspectRatio
35+
src
36+
srcSet
37+
srcWebp
38+
srcSetWebp
39+
sizes
40+
originalImg
41+
originalName
42+
presentationWidth
43+
presentationHeight
44+
}
45+
}
46+
}
47+
}
48+
parent {
49+
... on File {
50+
sourceInstanceName
51+
absolutePath
52+
relativePath
53+
name
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
`
61+
).then(result => {
62+
if (result.errors) {
63+
reject(result.errors);
64+
}
65+
66+
// Create blog posts pages.
67+
result.data.allMdx.edges.forEach(({ node }) => {
68+
createPage({
69+
path: `/posts/${node.frontmatter.slug}`,
70+
component: node.parent.absolutePath,
71+
context: {
72+
absPath: node.parent.absolutePath,
73+
timeToRead: node.timeToRead,
74+
cover: node.frontmatter.cover,
75+
tableOfContents: node.tableOfContents,
76+
},
77+
});
78+
});
79+
80+
})
81+
);
82+
});
83+
};
84+
85+
exports.onCreateWebpackConfig = ({ actions }) => {
86+
actions.setWebpackConfig({
87+
resolve: {
88+
alias: {
89+
'@mdx-js/react': path.resolve('./node_modules/@mdx-js/react'),
90+
react: path.resolve('./node_modules/react'),
91+
'react-dom': path.resolve('./node_modules/react-dom'),
92+
},
93+
},
94+
});
95+
};
96+
97+
exports.onPostBuild = async ({ graphql }) => {
98+
const data = await graphql(`
99+
{
100+
allMdx {
101+
edges {
102+
node {
103+
frontmatter {
104+
title
105+
}
106+
}
107+
}
108+
}
109+
}
110+
`).then(r => {
111+
if (r.errors) {
112+
// eslint-disable-next-line no-console
113+
console.error(r.errors.join(`, `));
114+
}
115+
return r.data;
116+
});
117+
118+
const titles = data.allMdx.edges.map(
119+
({
120+
node: {
121+
frontmatter: { title },
122+
},
123+
}) => ({
124+
id: slugify(title),
125+
title,
126+
})
127+
);
128+
129+
await runScreenshots({
130+
data: titles,
131+
component: require.resolve('./src/components/Printer/index.js'),
132+
outputDir: 'opengraph-images',
133+
});
134+
};

0 commit comments

Comments
 (0)