Tidy
This commit is contained in:
parent
c473ed5412
commit
1335632304
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "esbuild ssg/build.tsx --bundle --outfile=.tmp/ssg/build.js --jsx-import-source=@kitajs/html --minify --sourcemap --platform=node --external:esbuild --external:prettier",
|
"compile": "esbuild ssg/build.tsx --bundle --outfile=.tmp/ssg/build.js --jsx-import-source=@kitajs/html --minify --sourcemap --platform=node --external:esbuild --external:prettier",
|
||||||
"buld": "npm run compile && node .tmp/ssg/build.js"
|
"build": "npm run compile && node .tmp/ssg/build.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import matter from 'gray-matter';
|
import matter from 'gray-matter';
|
||||||
import { parse } from 'marked';
|
import { parse } from 'marked';
|
||||||
import { getPaths, getStylePath } from './utils';
|
import { buildFile, getStylePath } from './utils';
|
||||||
import { build } from 'esbuild';
|
|
||||||
import { sassPlugin } from 'esbuild-sass-plugin';
|
|
||||||
import { format } from 'prettier';
|
import { format } from 'prettier';
|
||||||
import Root from './root';
|
import Root from './root';
|
||||||
import { writeFileSync } from 'node:fs';
|
import { writeFileSync } from 'node:fs';
|
||||||
@ -11,7 +9,6 @@ import { resolve } from 'path';
|
|||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
|
|
||||||
export const buildBlog = async (blog: string) => {
|
export const buildBlog = async (blog: string) => {
|
||||||
console.log(`Building ${blog}`);
|
|
||||||
const fileContent = await readFile(blog, 'utf-8');
|
const fileContent = await readFile(blog, 'utf-8');
|
||||||
const content = matter(fileContent);
|
const content = matter(fileContent);
|
||||||
const postHtml = parse(content.content);
|
const postHtml = parse(content.content);
|
||||||
@ -33,25 +30,7 @@ export const buildBlog = async (blog: string) => {
|
|||||||
.replace(content.data.template, blogFileName)
|
.replace(content.data.template, blogFileName)
|
||||||
.replace('.tsx', '.html');
|
.replace('.tsx', '.html');
|
||||||
|
|
||||||
await build({
|
await buildFile(templatePath, tmpJsPath);
|
||||||
entryPoints: [templatePath],
|
|
||||||
bundle: true,
|
|
||||||
outfile: tmpJsPath,
|
|
||||||
jsxImportSource: '@kitajs/html',
|
|
||||||
minify: true,
|
|
||||||
platform: 'node',
|
|
||||||
external: ['esbuild'],
|
|
||||||
plugins: [
|
|
||||||
sassPlugin({
|
|
||||||
filter: /\.module\.scss$/,
|
|
||||||
type: 'local-css',
|
|
||||||
}),
|
|
||||||
sassPlugin({
|
|
||||||
filter: /\.scss$/,
|
|
||||||
type: 'css',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const { default: Page } = await import(tmpJsPath);
|
const { default: Page } = await import(tmpJsPath);
|
||||||
const html = Page.default({ children: postHtml });
|
const html = Page.default({ children: postHtml });
|
||||||
|
@ -1,32 +1,12 @@
|
|||||||
import { getPaths, getStylePath } from './utils';
|
import { buildFile, getPagePaths, getStylePath } from './utils';
|
||||||
import { build } from 'esbuild';
|
|
||||||
import { sassPlugin } from 'esbuild-sass-plugin';
|
|
||||||
import { format } from 'prettier';
|
import { format } from 'prettier';
|
||||||
import Root from './root';
|
import Root from './root';
|
||||||
import { writeFileSync } from 'node:fs';
|
import { writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
export const buildPage = async (page: string) => {
|
export const buildPage = async (page: string) => {
|
||||||
const { pagePath, tmpJsPath, pageOutputHtmlPath } = getPaths(page);
|
const { pagePath, tmpJsPath, pageOutputHtmlPath } = getPagePaths(page);
|
||||||
|
|
||||||
await build({
|
await buildFile(pagePath, tmpJsPath);
|
||||||
entryPoints: [pagePath],
|
|
||||||
bundle: true,
|
|
||||||
outfile: tmpJsPath,
|
|
||||||
jsxImportSource: '@kitajs/html',
|
|
||||||
minify: true,
|
|
||||||
platform: 'node',
|
|
||||||
external: ['esbuild'],
|
|
||||||
plugins: [
|
|
||||||
sassPlugin({
|
|
||||||
filter: /\.module\.scss$/,
|
|
||||||
type: 'local-css',
|
|
||||||
}),
|
|
||||||
sassPlugin({
|
|
||||||
filter: /\.scss$/,
|
|
||||||
type: 'css',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const { default: Page } = await import(tmpJsPath);
|
const { default: Page } = await import(tmpJsPath);
|
||||||
const html = Page.default();
|
const html = Page.default();
|
||||||
|
25
ssg/utils.ts
25
ssg/utils.ts
@ -1,5 +1,7 @@
|
|||||||
import { cpSync, existsSync } from 'node:fs';
|
import { cpSync, existsSync } from 'node:fs';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
import { sassPlugin } from 'esbuild-sass-plugin';
|
||||||
|
import { build } from 'esbuild';
|
||||||
|
|
||||||
export const outDir = resolve('.out');
|
export const outDir = resolve('.out');
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ export const getStylePath = (tmpJsPath: string, pageOutputHtmlPath: string) => {
|
|||||||
return stylePaths;
|
return stylePaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPaths = (rawPath: string) => {
|
export const getPagePaths = (rawPath: string) => {
|
||||||
const pagePath = resolve(rawPath);
|
const pagePath = resolve(rawPath);
|
||||||
const tmpJsPath = pagePath.replace('src', '.tmp').replace('.tsx', '.js');
|
const tmpJsPath = pagePath.replace('src', '.tmp').replace('.tsx', '.js');
|
||||||
const pageOutputHtmlPath = pagePath
|
const pageOutputHtmlPath = pagePath
|
||||||
@ -32,3 +34,24 @@ export const getPaths = (rawPath: string) => {
|
|||||||
|
|
||||||
return { pagePath, tmpJsPath, pageOutputHtmlPath, blogOutputHtmlPath };
|
return { pagePath, tmpJsPath, pageOutputHtmlPath, blogOutputHtmlPath };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const buildFile = async (input: string, output: string) =>
|
||||||
|
await build({
|
||||||
|
entryPoints: [input],
|
||||||
|
bundle: true,
|
||||||
|
outfile: output,
|
||||||
|
jsxImportSource: '@kitajs/html',
|
||||||
|
minify: true,
|
||||||
|
platform: 'node',
|
||||||
|
external: ['esbuild'],
|
||||||
|
plugins: [
|
||||||
|
sassPlugin({
|
||||||
|
filter: /\.module\.scss$/,
|
||||||
|
type: 'local-css',
|
||||||
|
}),
|
||||||
|
sassPlugin({
|
||||||
|
filter: /\.scss$/,
|
||||||
|
type: 'css',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user