Skip to content

Commit ce3b9e9

Browse files
committed
🎉
1 parent cb51d15 commit ce3b9e9

62 files changed

Lines changed: 46601 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.cache/
3+
public
4+
.idea/*
5+
*.iml
6+
.env
7+
.DS_Store

gatsby-config.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
require('dotenv').config({
3+
path: `.env`,
4+
});
5+
6+
const pageQuery = `{
7+
docs: allMarkdownRemark(
8+
filter: {
9+
fileAbsolutePath: { regex: "/tutorials/" },
10+
}
11+
) {
12+
edges {
13+
node {
14+
headings(depth: h3) {
15+
value
16+
}
17+
objectID: id
18+
frontmatter {
19+
title
20+
search_keyword
21+
contextual_links {
22+
type
23+
name
24+
url
25+
}
26+
}
27+
fields {
28+
slug
29+
}
30+
excerpt(
31+
pruneLength: 6700
32+
)
33+
}
34+
}
35+
}
36+
}`;
37+
38+
39+
function pageToAlgoliaRecord({ node: { id, frontmatter, ...rest } }) {
40+
return {
41+
objectID: id,
42+
...frontmatter,
43+
...rest,
44+
};
45+
}
46+
47+
const settings = { attributesToSnippet: ['excerpt:20'] };
48+
49+
const queries = [
50+
{
51+
query: pageQuery,
52+
transformer: ({ data }) => data.docs.edges.map(pageToAlgoliaRecord),
53+
indexName: 'OS Docs',
54+
settings,
55+
},
56+
];
57+
58+
59+
module.exports = {
60+
assetPrefix: `https://d9g73a6nhcae6.cloudfront.net`,
61+
siteMetadata: {
62+
title: 'Testsigma Tutorials',
63+
description: '',
64+
author: 'Testsigma',
65+
siteUrl: 'https://testsigma.com/tutorials/'
66+
},
67+
plugins: [
68+
"gatsby-plugin-postcss",
69+
"gatsby-plugin-sass",
70+
"gatsby-plugin-image",
71+
"gatsby-transformer-remark",
72+
"gatsby-plugin-sharp",
73+
"gatsby-transformer-sharp",
74+
{
75+
resolve: `gatsby-plugin-s3`,
76+
options: {
77+
bucketName: "tutorials.testsigma.com",
78+
protocol: "https",
79+
hostname: "testsigma.com/tutorials/",
80+
generateRedirectObjectsForPermanentRedirects: true
81+
},
82+
},
83+
{
84+
resolve: 'gatsby-source-filesystem',
85+
options: {
86+
name: 'src',
87+
path: `${__dirname}/src/`,
88+
},
89+
},
90+
{
91+
resolve: 'gatsby-plugin-algolia',
92+
options: {
93+
appId: process.env.GATSBY_ALGOLIA_APP_ID,
94+
apiKey: process.env.ALGOLIA_ADMIN_KEY,
95+
queries,
96+
chunkSize: 10000, // default: 1000
97+
enablePartialUpdates: true, // only index new, changed, deleted records
98+
matchFields: ['excerpt', 'contextual_links', 'search_keyword', 'headings', 'fields', 'modified'],
99+
concurrentQueries: false,
100+
},
101+
},
102+
{
103+
resolve: 'gatsby-transformer-remark',
104+
options: {
105+
plugins: [
106+
{
107+
resolve: `gatsby-remark-autolink-headers`,
108+
options: {
109+
elements: [`h2`],
110+
},
111+
},
112+
'gatsby-remark-check-links',
113+
'gatsby-remark-responsive-iframe',
114+
{
115+
resolve: 'gatsby-remark-prismjs',
116+
options: {
117+
classPrefix: 'language-',
118+
inlineCodeMarker: null,
119+
aliases: {},
120+
showLineNumbers: false,
121+
noInlineHighlight: false,
122+
},
123+
},
124+
{
125+
resolve: "gatsby-remark-custom-blocks",
126+
options: {
127+
blocks: {
128+
danger: {
129+
classes: "alert alert-danger",
130+
title: "optional",
131+
},
132+
info: {
133+
classes: "alert alert-info",
134+
title: "optional",
135+
},
136+
},
137+
},
138+
}
139+
],
140+
},
141+
}
142+
],
143+
};

gatsby-node.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
const path = require('path');
2+
const glob = require('glob');
3+
const fs = require('fs');
4+
const frontmatter = require('@github-docs/frontmatter');
5+
const { v4: uuidv4 } = require('uuid');
6+
const { createFilePath } = require('gatsby-source-filesystem');
7+
const redirects = require('./src/redirects.json');
8+
9+
const ignorePaths = [];
10+
11+
exports.onCreateNode = ({ node, getNode, actions }) => {
12+
const { createNodeField } = actions;
13+
if (node.internal.type === 'MarkdownRemark') {
14+
const slug = createFilePath({ node, getNode, basePath: 'pages' });
15+
createNodeField({
16+
node,
17+
name: 'slug',
18+
value: slug,
19+
});
20+
}
21+
};
22+
23+
24+
exports.createPages = async ({ graphql, actions }) => {
25+
const { createRedirect, createPage } = actions;
26+
27+
redirects.forEach(({ from, to }) => {
28+
createRedirect({
29+
fromPath: from,
30+
isPermanent: true,
31+
redirectInBrowser: true,
32+
toPath: to,
33+
});
34+
});
35+
36+
const result = await graphql(`
37+
query {
38+
allMarkdownRemark(sort: {fields: frontmatter___order, order: ASC}) {
39+
edges {
40+
node {
41+
fields {
42+
slug
43+
}
44+
frontmatter {
45+
title
46+
}
47+
}
48+
}
49+
}
50+
}
51+
`);
52+
result.data.allMarkdownRemark.edges.forEach(({ node }, index) => {
53+
if (node.fields.slug.includes('-')) {
54+
const underscoreSlug = node.fields.slug.replace(/-/g, '_');
55+
56+
createRedirect({
57+
fromPath: underscoreSlug,
58+
isPermanent: true,
59+
redirectInBrowser: true,
60+
toPath: node.fields.slug,
61+
});
62+
}
63+
createPage({
64+
path: node.fields.slug,
65+
component: path.resolve('./src/templates/page.jsx'),
66+
context: {
67+
slug: node.fields.slug,
68+
prev: index === 0 ? null : result.data.allMarkdownRemark.edges[index - 1].node,
69+
next: index === result.data.allMarkdownRemark.edges.length - 1 ? null : result.data.allMarkdownRemark.edges[index + 1].node
70+
},
71+
});
72+
});
73+
};
74+
75+
76+
77+
/* Create Header and Footer
78+
/************************************************************************ */
79+
exports.sourceNodes = async ({
80+
actions,
81+
createNodeId,
82+
createContentDigest,
83+
}) => {
84+
const prepareNode = (obj, name) => {
85+
const data = {
86+
key: uuidv4(),
87+
value: JSON.stringify(obj),
88+
};
89+
const node = JSON.stringify(data);
90+
const nodeMeta = {
91+
id: createNodeId(`my-data-${data.key}`),
92+
parent: null,
93+
children: [],
94+
internal: {
95+
type: name,
96+
mediaType: 'text/json',
97+
content: node,
98+
contentDigest: createContentDigest(data),
99+
},
100+
};
101+
102+
const output = { ...data, ...nodeMeta };
103+
return output;
104+
};
105+
106+
const { createNode } = actions;
107+
108+
const getDirectories = (src) => glob.sync(`${src}/**/*`);
109+
const paths = getDirectories('./src/pages/tutorials')
110+
.filter((val) => val.slice(-3) === '.md')
111+
.map((val) => {
112+
const { data } = frontmatter(fs.readFileSync(val));
113+
const order = data.order || 200;
114+
return [val, order];
115+
})
116+
.sort((a, b) => Number(a[1]) - Number(b[1]))
117+
.map((val) => {
118+
let newVal = '';
119+
newVal = val[0].replace(/\.\/src\/pages/g, '');
120+
newVal = newVal.substring(0, newVal.length - 3);
121+
newVal = newVal.slice(-5) === 'index' ? newVal.substring(0, newVal.length - 5) : newVal;
122+
return `${newVal}/`;
123+
})
124+
.filter((val) => !ignorePaths.includes(val));
125+
126+
const output = {};
127+
128+
paths.forEach((val) => {
129+
let split = val.split('/');
130+
split = split.filter((url) => url !== '');
131+
132+
let current = output;
133+
split.forEach((part) => {
134+
current[part] = current[part] || {};
135+
current = current[part];
136+
});
137+
current.url = `/${split.join('/')}/`;
138+
});
139+
140+
createNode(prepareNode(output.tutorials, 'leftNavLinks'));
141+
};

0 commit comments

Comments
 (0)