fix: SEO-1 (#29)

This commit is contained in:
Eric Tuvesson
2023-09-22 12:35:24 +02:00
committed by GitHub
parent d392dd0407
commit f3b8bb4d3b
111 changed files with 222 additions and 203 deletions

View File

@@ -1,58 +1,64 @@
const fs = require('fs')
const path = require('path')
function resolveImports(content,dir) {
function resolveImports(content, dir) {
const includeMatch = content.matchAll(/@include\s\"(.*)\"/g)
for(const _s of includeMatch) {
for (const _s of includeMatch) {
const includePath = _s[1];
const absPath = path.join(dir,includePath)
const absPath = path.join(dir, includePath)
const include = fs.readFileSync(absPath)
content = content.replace(_s[0],include)
content = content.replace(_s[0], include)
}
return content
}
function copyNodeMarkdowns(dir) {
fs.readdirSync(dir).forEach(file => {
if( fs.lstatSync(dir + '/' + file).isDirectory() ) {
copyNodeMarkdowns(dir + '/' + file)
}
else if(file.endsWith('.md')) {
const content = fs.readFileSync(dir + '/' + file)
const resolved = resolveImports(content.toString(),dir)
const filePath = 'build/' + dir + '/' + file;
if (!fs.existsSync('build/' + dir)){
function copyNodeMarkdowns(dir, asFolderName) {
fs.readdirSync(dir).forEach(function (file) {
if (fs.lstatSync(dir + '/' + file).isDirectory()) {
copyNodeMarkdowns(dir + '/' + file, asFolderName)
} else if (file.endsWith('.md')) {
const filePath = path.join(dir, file);
const content = fs.readFileSync(filePath)
const resolved = resolveImports(content.toString(), dir)
let outputFilePath = 'build/' + filePath;
if (asFolderName) {
// HACK: Resolve the new nodes folder structure
outputFilePath = 'build/' + filePath.split("\\").slice(0, -1).join("/") + '.md'
}
if (!fs.existsSync('build/' + dir)) {
fs.mkdirSync('build/' + dir);
}
fs.writeFileSync(filePath, resolved)
fs.writeFileSync(outputFilePath, resolved)
}
})
}
module.exports = function(context, options) {
module.exports = function (context, options) {
return {
name: 'docusaurus-copy-node-markdowns-plugin',
configureWebpack(config, isServer, utils) {
const {getJSLoader} = utils;
return isServer?{
plugins: [
{
name: 'docusaurus-copy-node-markdowns-plugin',
configureWebpack(config, isServer, utils) {
const {
getJSLoader
} = utils;
return isServer ? {
plugins: [{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
console.log('Copying node markdown files')
options.paths.forEach(path => {
console.log(' - Processing path: ' + path)
copyNodeMarkdowns(path)
console.log(' - Processing path: ' + path.path)
copyNodeMarkdowns(path.path, !!path.folderName)
})
})
}
}
]
}:{}
},
}]
} : {}
},
};
};
};