Skip to content

Commit

Permalink
chore: update to gatsby v5 and node v18
Browse files Browse the repository at this point in the history
  • Loading branch information
tc-imba committed Nov 13, 2023
1 parent f9faaf2 commit 2241a2b
Show file tree
Hide file tree
Showing 24 changed files with 6,463 additions and 6,813 deletions.
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"clean": "gatsby clean"
},
"dependencies": {
"gatsby": "^3.14.0",
"gatsby": "^5.12.9",
"gatsby-theme-academic": "*",
"react": "^16.14.0",
"react-dom": "^16.14.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
39 changes: 37 additions & 2 deletions gatsby-theme-academic/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
/* eslint-disable global-require */
/*
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeKatex from 'rehype-katex';
import rehypeSlug from 'rehype-slug';
import remarkAbbr from 'remark-abbr';
import remarkExternalLinks from 'remark-external-links';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const esmrequire = require('./src/utils/esmrequire');
*/

module.exports = ({
contentPath = 'content',
author = '',
Expand Down Expand Up @@ -31,8 +48,26 @@ module.exports = ({
},
},
'gatsby-plugin-react-helmet',
{
resolve: 'gatsby-plugin-sharp',
options: {
defaults: {
formats: ['auto', 'webp'],
placeholder: 'dominantColor',
quality: 50,
breakpoints: [750, 1080, 1366, 1920],
backgroundColor: 'transparent',
tracedSVGOptions: {},
blurredOptions: {},
jpgOptions: {},
pngOptions: {},
webpOptions: {},
avifOptions: {},
},
},
},
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
'gatsby-plugin-image',
{
resolve: 'gatsby-plugin-less',
options: {
Expand Down Expand Up @@ -72,7 +107,7 @@ module.exports = ({
},
},
{
resolve: 'gatsby-plugin-mdx',
resolve: 'gatsby-plugin-mdx-v1',
options: {
extensions: ['.mdx', '.md'],
remarkPlugins: [
Expand Down
174 changes: 95 additions & 79 deletions gatsby-theme-academic/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,43 @@
/* eslint-disable guard-for-in */

/* Vendor imports */
/* import * as crypto from 'crypto';
import { createRequire } from 'module';
import * as path from 'path';
import { $ as execa } from 'execa';
import fs from 'fs-extra';
import _ from 'lodash';
import slash from 'slash';
import nacl from 'tweetnacl';
import naclUtil from 'tweetnacl-util';
import utils from './src/utils/pageUtils.js';
const require = createRequire(import.meta.url); */

const esmrequire = require('./src/utils/esmrequire');
const crypto = require('crypto');
const path = require('path');

const execa = require('execa');
const execa = esmrequire('execa');
const fs = require('fs-extra');
const _ = require('lodash');
const slash = require('slash');

const slash = esmrequire('slash');
const nacl = require('tweetnacl');
nacl.util = require('tweetnacl-util');
const naclUtil = require('tweetnacl-util');
// const isRelativeUrl = require('is-relative-url');

/* App imports */
const utils = require('./src/utils/pageUtils');
const utils = require('./src/utils/commonUtils');

const getGitInfo = () => {
const gitHash = execa.sync('git', ['rev-parse', '--short', 'HEAD']).stdout;
const gitNumCommits = Number(
execa.sync('git', ['rev-list', 'HEAD', '--count']).stdout,
);
const gitDirty =
execa.sync('git', ['status', '-s', '-uall']).stdout.length > 0;
execa.sync('git', ['status', '-s', '-uall']).stdout.length > 0;
return {
hash: gitHash,
commits: gitNumCommits,
Expand Down Expand Up @@ -107,7 +123,7 @@ exports.createPages = async ({

const result = await graphql(`
{
allMdx(sort: { order: DESC, fields: [frontmatter___date] }) {
allMdx(sort: {frontmatter: {date: DESC}}) {
edges {
node {
body
Expand Down Expand Up @@ -188,7 +204,7 @@ exports.createPages = async ({
// Check path prefix of Post and Research
if (
frontmatter.path.indexOf(options.pages.posts) !== 0 &&
frontmatter.path.indexOf(options.pages.research) !== 0
frontmatter.path.indexOf(options.pages.research) !== 0
) {
// eslint-disable-next-line no-throw-literal
throw `Invalid path prefix: ${frontmatter.path}`;
Expand All @@ -215,14 +231,14 @@ exports.createPages = async ({
// encrypt post with password
if (frontmatter.password) {
const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);
const message = nacl.util.decodeUTF8(node.body);
const password = nacl.util.decodeUTF8(frontmatter.password);
const message = naclUtil.decodeUTF8(node.body);
const password = naclUtil.decodeUTF8(frontmatter.password);
const key = nacl.hash(password)
.slice(0, nacl.secretbox.keyLength);
const htmlEncrypted = nacl.secretbox(message, nonce, key);
data.html = '';
data.htmlEncrypted = nacl.util.encodeBase64(htmlEncrypted);
data.nonce = nacl.util.encodeBase64(nonce);
data.htmlEncrypted = naclUtil.encodeBase64(htmlEncrypted);
data.nonce = naclUtil.encodeBase64(nonce);
} else {
data.html = node.body;
data.htmlEncrypted = '';
Expand Down Expand Up @@ -268,17 +284,17 @@ exports.createPages = async ({
}

/* if (link.file && link.file.internal && link.file.base && link.file.absolutePath) {
const { contentDigest } = link.file.internal;
const destFileDir = path.posix.join('public', 'files', contentDigest);
const destFilePath = path.posix.join(destFileDir, link.file.base);
const urlFilePath = utils.resolveUrl('files', contentDigest, link.file.base);
fs.ensureDirSync(destFileDir);
fs.copyFileSync(link.file.absolutePath, destFilePath);
data.links.push({
name: link.name,
url: urlFilePath,
});
} */
const { contentDigest } = link.file.internal;
const destFileDir = path.posix.join('public', 'files', contentDigest);
const destFilePath = path.posix.join(destFileDir, link.file.base);
const urlFilePath = utils.resolveUrl('files', contentDigest, link.file.base);
fs.ensureDirSync(destFileDir);
fs.copyFileSync(link.file.absolutePath, destFilePath);
data.links.push({
name: link.name,
url: urlFilePath,
});
} */

if (frontmatter.tags) {
for (let i = 0; i < frontmatter.tags.length; i++) {
Expand Down Expand Up @@ -389,53 +405,53 @@ exports.onCreateNode = ({
}
}
/* else if (node.internal.type === 'MarkdownRemark') {
const { frontmatter } = node;
const data = {};
data.title = frontmatter.title || '';
data.tags = frontmatter.tags || [];
data.date = frontmatter.date || '';
data.path = frontmatter.path;
data.excerpt = frontmatter.excerpt || '';
data.links = [];
if (frontmatter.links) {
for (const link of frontmatter.links) {
if (link.name) {
let href = '';
console.log(link.url);
if (
isRelativeUrl(link.url)
&& getNode(node.parent).internal.type === 'File'
) {
const linkPath = path.posix.join(
getNode(node.parent).dir,
link.url,
);
const fileNode = getNodeByAbsolutePath(linkPath);
console.log(linkPath, fileNode);
const { frontmatter } = node;
const data = {};
data.title = frontmatter.title || '';
data.tags = frontmatter.tags || [];
data.date = frontmatter.date || '';
data.path = frontmatter.path;
data.excerpt = frontmatter.excerpt || '';
data.links = [];
if (frontmatter.links) {
for (const link of frontmatter.links) {
if (link.name) {
let href = '';
console.log(link.url);
if (
isRelativeUrl(link.url)
&& getNode(node.parent).internal.type === 'File'
) {
const linkPath = path.posix.join(
getNode(node.parent).dir,
link.url,
);
const fileNode = getNodeByAbsolutePath(linkPath);
console.log(linkPath, fileNode);
}
// if (link.file) {
// const linkPath = path.posix.join(
// getNode(markdownNode.parent).dir,
// link.url,
// );
// console.log(link.file);
// } else if (link.href) {
// href = link.href;
// }
// data.links.push({
// name: link.name,
// href,
// });
}
// if (link.file) {
// const linkPath = path.posix.join(
// getNode(markdownNode.parent).dir,
// link.url,
// );
// console.log(link.file);
// } else if (link.href) {
// href = link.href;
// }
// data.links.push({
// name: link.name,
// href,
// });
}
}
}
// console.log(node);
// createNodeField({
// node,
// name: 'slug',
// value: data,
// });
} */
// console.log(node);
// createNodeField({
// node,
// name: 'slug',
// value: data,
// });
} */
};

exports.createSchemaCustomization = async (
Expand Down Expand Up @@ -598,19 +614,19 @@ exports.createSchemaCustomization = async (
});

/* const fileDef = schema.buildObjectType({
name: 'File',
id: {
type: 'String!',
resolve(source, args, context, info) {
// For a more generic solution, you could pick the field value from
// `source[info.fieldName]`
if (source.id == null) {
return '';
}
return source.id;
name: 'File',
id: {
type: 'String!',
resolve(source, args, context, info) {
// For a more generic solution, you could pick the field value from
// `source[info.fieldName]`
if (source.id == null) {
return '';
}
return source.id;
},
},
},
}); */
}); */
createTypes([MdxFrontmatterDef, typeDefs]);
};

Expand Down
Loading

0 comments on commit 2241a2b

Please sign in to comment.