Skip to content

Commit

Permalink
feat(root): add stackblitz button and add new variant of "copy code" …
Browse files Browse the repository at this point in the history
…button for small screen sizes

Add new optional Stackblitz button to ComponentPreview & CodePreview components, connect Stackblitz
SDK to onClick of StackblitzButton component, add cleanup function to useEffect in CookieData
component

. #751
  • Loading branch information
GCHQ-Developer-112 committed Mar 22, 2024
1 parent 974c914 commit 3b43731
Show file tree
Hide file tree
Showing 12 changed files with 1,002 additions and 125 deletions.
55 changes: 55 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require(`path`);
const fs = require("fs");
// eslint-disable-next-line import/no-extraneous-dependencies
const webpack = require("webpack");
const pagesConfig = require("./src/config");
Expand Down Expand Up @@ -236,6 +237,11 @@ exports.createResolvers = ({ createResolvers }) => {

exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
fallback: {
fs: false,
},
},
plugins: [
/**
* See line 203 of:
Expand Down Expand Up @@ -277,3 +283,52 @@ exports.onCreateWebpackConfig = ({ actions }) => {
],
});
};

exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions;

// Read all files in the sub-directories of the patterns folder
function getFilePaths(dirPath) {
let filePaths = [];
const files = fs.readdirSync(dirPath);

files.forEach((file) => {
const absolutePath = path.join(dirPath, file);
if (fs.statSync(absolutePath).isDirectory()) {
filePaths = filePaths.concat(getFilePaths(absolutePath));
} else {
filePaths.push(absolutePath);
}
});

return filePaths;
}

// Read all files in the patterns folder
const patternsDir = path.resolve(
__dirname,
"src/content/structured/patterns/templates"
);
const filePaths = getFilePaths(patternsDir);

// For each file in the patterns folder, read the contents of the file and create a data node
filePaths.forEach((filePath) => {
const content = fs.readFileSync(filePath, "utf8");
const regex = /(?:\\|\/)patterns(?:\\|\/)templates((?:\\|\/).*)$/;
const regexMatchedFilePath = filePath.match(regex)[0];

const nodeMeta = {
id: createNodeId(`${regexMatchedFilePath}`),
parent: null,
children: [],
internal: {
type: `PatternsTemplates`,
contentFilePath: regexMatchedFilePath,
content,
contentDigest: createContentDigest(content),
},
};

createNode(nodeMeta);
});
};
Loading

0 comments on commit 3b43731

Please sign in to comment.