mirror of
https://github.com/Yet-Another-DreamTeam/extended-markdown.git
synced 2026-03-13 00:07:24 +00:00
functional prototype
This commit is contained in:
parent
43893be542
commit
ac707e4248
@ -1 +1,7 @@
|
||||
# Header
|
||||
# Header
|
||||
|
||||
Hallo
|
||||
|
||||
*1
|
||||
*2
|
||||
*3
|
||||
79
index.js
79
index.js
@ -1,28 +1,69 @@
|
||||
const { readdirSync, statSync, readFileSync } = require("fs");
|
||||
const { join } = require("path");
|
||||
const {
|
||||
readdirSync,
|
||||
statSync,
|
||||
readFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
writeFileSync,
|
||||
} = require("fs");
|
||||
const { join, sep } = require("path");
|
||||
|
||||
function getFilesFromFolder(staticpath) {
|
||||
let results = readdirSync(staticpath);
|
||||
let folders = [];
|
||||
function getFilesFromDirectoryRecursive(staticpath, relativepath) {
|
||||
const fileNames = readdirSync(staticpath);
|
||||
let files = [];
|
||||
results.forEach((result) => {
|
||||
result = join(staticpath, result);
|
||||
if (statSync(result).isDirectory()) {
|
||||
folders.push(result);
|
||||
const folderfiles = getFilesFromFolder(result);
|
||||
folderfiles.forEach((folderfile) => files.push(folderfile));
|
||||
} else if (statSync(result).isFile()) {
|
||||
files.push(result);
|
||||
fileNames.forEach((file) => {
|
||||
if (statSync(join(staticpath, file)).isDirectory()) {
|
||||
files = [
|
||||
...files,
|
||||
...getFilesFromDirectoryRecursive(
|
||||
join(staticpath, file),
|
||||
join(relativepath, file)
|
||||
),
|
||||
];
|
||||
} else if (statSync(join(staticpath, file)).isFile()) {
|
||||
files.push({
|
||||
relative: join(relativepath, file),
|
||||
static: join(staticpath, file),
|
||||
data: readFileSync(join(staticpath, file), "utf-8"),
|
||||
});
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
let templatePaths = getFilesFromFolder(join(__dirname, "./templates"));
|
||||
let componentPaths = getFilesFromFolder(join(__dirname, "./components"));
|
||||
let templates = templatePaths.map((path) => {
|
||||
return { path: path, data: readFileSync(path, "utf-8") };
|
||||
let files = getFilesFromDirectoryRecursive(join(__dirname, "./templates"), "");
|
||||
|
||||
files.forEach((file) => {
|
||||
const folders = file.relative.split(sep).slice(0, -1);
|
||||
if (folders.length === 0) return;
|
||||
let path = join(__dirname + "/output");
|
||||
folders.forEach((filePath) => {
|
||||
path = join(path, filePath);
|
||||
if (!existsSync(path)) {
|
||||
console.log(path);
|
||||
mkdirSync(path);
|
||||
}
|
||||
return path;
|
||||
});
|
||||
});
|
||||
|
||||
console.log("Templates:", templates);
|
||||
// console.log("Templates:", components);
|
||||
let outputFiles = []
|
||||
|
||||
files.forEach((file) => {
|
||||
const includes = [
|
||||
...file.data.matchAll(/<include>[a-zA-Z0-9]+.emd<\/include>/g),
|
||||
];
|
||||
includes.forEach((include) => {
|
||||
const path = include[0].replace(/<include>/, "").replace(/<\/include>/, "")
|
||||
const includedata = readFileSync(join(__dirname ,"/components", path), "utf-8");
|
||||
file.data = file.data.replace("<include>" + path + "</include>", includedata)
|
||||
});
|
||||
outputFiles.push(file)
|
||||
});
|
||||
|
||||
files.forEach((file) => {
|
||||
writeFileSync(
|
||||
join(__dirname, "/output", file.relative.replace(".emd", ".md")),
|
||||
file.data
|
||||
);
|
||||
});
|
||||
|
||||
6
templates/Hallo/Hallo.emd
Normal file
6
templates/Hallo/Hallo.emd
Normal file
@ -0,0 +1,6 @@
|
||||
<include>header.emd</include>
|
||||
<include>header.emd</include>
|
||||
<include>header.emd</include>
|
||||
<include>header.emd</include>
|
||||
<include>header.emd</include>
|
||||
<include>header.emd</include>
|
||||
3
templates/Index.emd
Normal file
3
templates/Index.emd
Normal file
@ -0,0 +1,3 @@
|
||||
<include>header.emd</include>
|
||||
|
||||
# Index
|
||||
@ -1,3 +1,5 @@
|
||||
<include>header</include>
|
||||
<include>header.emd</include>
|
||||
|
||||
# Login
|
||||
# Login
|
||||
|
||||
<include>header.emd</include>
|
||||
@ -1,3 +1,3 @@
|
||||
<include>header</include>
|
||||
<include>header.emd</include>
|
||||
|
||||
# Register
|
||||
1
templates/Users/Home.emd
Normal file
1
templates/Users/Home.emd
Normal file
@ -0,0 +1 @@
|
||||
<include>header.emd</include>
|
||||
@ -1,3 +0,0 @@
|
||||
<include>header</include>
|
||||
|
||||
# Index
|
||||
Loading…
x
Reference in New Issue
Block a user