feat: 删除无用依赖,shiki lang使用懒加载方式加载语言
This commit is contained in:
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@@ -0,0 +1,10 @@
|
||||
node_modules/
|
||||
.git/
|
||||
.idea/
|
||||
dist/
|
||||
.astro/
|
||||
.vscode/
|
||||
.claude/
|
||||
*.tar.gz
|
||||
*.log
|
||||
.DS_Store
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
import {defineConfig} from 'astro/config';
|
||||
import solidJs from '@astrojs/solid-js';
|
||||
import node from '@astrojs/node';
|
||||
|
||||
// https://astro.build/config
|
||||
@@ -10,16 +9,14 @@ export default defineConfig({
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
},
|
||||
integrations: [solidJs()],
|
||||
adapter: node({
|
||||
mode: 'standalone'
|
||||
}),
|
||||
vite: {
|
||||
plugins: [],
|
||||
server: {
|
||||
watch: {
|
||||
usePolling: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
...(process.argv.includes('dev')
|
||||
? {watch: {usePolling: true}}
|
||||
: {}),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,17 +11,14 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "11.0.2",
|
||||
"@astrojs/solid-js": "^5.1.3",
|
||||
"astro": "^7.0.6",
|
||||
"clipboard": "^2.0.11",
|
||||
"dayjs": "^1.11.21",
|
||||
"github-markdown-css": "^5.9.0",
|
||||
"jsdom": "^29.1.1",
|
||||
"ky": "^2.0.2",
|
||||
"modern-normalize": "^3.0.1",
|
||||
"photoswipe": "^5.4.4",
|
||||
"shiki": "^4.3.1",
|
||||
"solid-js": "^1.9.14"
|
||||
"shiki": "^4.3.1"
|
||||
},
|
||||
"volta": {
|
||||
"node": "22.21.1"
|
||||
|
||||
1091
pnpm-lock.yaml
generated
1091
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
||||
FROM alpine:3.22 AS base
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache --update nodejs pnpm
|
||||
RUN apk add --no-cache --update nodejs
|
||||
|
||||
FROM base AS install
|
||||
RUN apk add --no-cache pnpm
|
||||
ENV NODE_ENV=production
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
FROM install AS build
|
||||
COPY . .
|
||||
|
||||
@@ -5,41 +5,37 @@ const DEFAULT_THEME = 'github-dark-dimmed'
|
||||
|
||||
const highlighter = await createHighlighter({
|
||||
themes: [DEFAULT_THEME],
|
||||
langs: [
|
||||
"bash",
|
||||
"json",
|
||||
"yaml",
|
||||
"xml",
|
||||
"html",
|
||||
"css",
|
||||
"scss",
|
||||
"javascript",
|
||||
"typescript",
|
||||
"jsx",
|
||||
"tsx",
|
||||
"vue",
|
||||
"markdown",
|
||||
"sql",
|
||||
"python",
|
||||
"go",
|
||||
"dockerfile",
|
||||
"nginx"
|
||||
]
|
||||
langs: []
|
||||
})
|
||||
|
||||
const resolveLang = (lang: string) => {
|
||||
const supported = highlighter.getLoadedLanguages?.() || []
|
||||
if (!lang) return 'text'
|
||||
if (supported.includes(lang)) return lang
|
||||
const SUPPORTED_LANGS = [
|
||||
"bash", "json", "yaml", "xml", "html", "css", "scss",
|
||||
"javascript", "typescript", "jsx", "tsx", "vue",
|
||||
"markdown", "sql", "python", "go", "dockerfile", "nginx"
|
||||
] as const
|
||||
|
||||
const loadedLangs = new Set<string>(['text'])
|
||||
|
||||
type SupportedLang = typeof SUPPORTED_LANGS[number]
|
||||
|
||||
const supportedSet = new Set<string>(SUPPORTED_LANGS)
|
||||
|
||||
const ensureLangLoaded = async (lang: string): Promise<string> => {
|
||||
if (lang === 'text' || loadedLangs.has(lang)) return lang
|
||||
if (!supportedSet.has(lang)) return 'text'
|
||||
try {
|
||||
await highlighter.loadLanguage(lang as SupportedLang)
|
||||
loadedLangs.add(lang)
|
||||
return lang
|
||||
} catch {
|
||||
return 'text'
|
||||
}
|
||||
}
|
||||
|
||||
export const processHtmlWithJsdom = async (rawHtml: string) => {
|
||||
|
||||
const dom = new JSDOM(rawHtml)
|
||||
const document = dom.window.document
|
||||
|
||||
// 高亮处理代码块
|
||||
const codeBlocks = document.querySelectorAll('pre code')
|
||||
|
||||
for (const codeBlock of codeBlocks) {
|
||||
@@ -55,9 +51,8 @@ export const processHtmlWithJsdom = async (rawHtml: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
lang = resolveLang(lang)
|
||||
lang = await ensureLangLoaded(lang) // ← 唯一改动点:按需加载
|
||||
|
||||
// 高亮
|
||||
const highlighted = highlighter.codeToHtml(codeContent, {
|
||||
lang,
|
||||
theme: DEFAULT_THEME,
|
||||
@@ -116,5 +111,5 @@ export const processHtmlWithJsdom = async (rawHtml: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
return dom.serialize()
|
||||
return document.body.innerHTML
|
||||
}
|
||||
|
||||
@@ -140,6 +140,8 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
||||
const article = document.querySelector(".markdown-body")!;
|
||||
const images = Array.from(article.querySelectorAll("img"));
|
||||
|
||||
if(images.length === 0) return
|
||||
|
||||
const waitImageLoaded = (img: HTMLImageElement) => {
|
||||
if (img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
||||
return Promise.resolve();
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "solid-js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user