doc.yeswiki.pro/node_modules/vitepress/dist/node-cjs/index.cjs
2023-05-20 19:38:02 +03:00

118 lines
3.3 KiB
JavaScript

'use strict';
var init = require('./serve-11470e0d.cjs');
var fs = require('fs');
var path = require('path');
var vite = require('vite');
require('dns');
require('node:process');
require('assert');
require('events');
require('node:readline');
require('stream');
require('buffer');
require('url');
require('crypto');
require('shiki');
require('child_process');
require('node:path');
require('minisearch');
require('module');
require('node:url');
require('node:fs');
require('tty');
require('util');
require('net');
require('zlib');
require('http');
require('querystring');
require('os');
require('node:tty');
require('constants');
function createContentLoader(pattern, {
includeSrc,
render,
excerpt: renderExcerpt,
transform
} = {}) {
const config = global.VITEPRESS_CONFIG;
if (!config) {
throw new Error(
"content loader invoked without an active vitepress process, or before vitepress config is resolved."
);
}
if (typeof pattern === "string")
pattern = [pattern];
pattern = pattern.map((p) => vite.normalizePath(path.join(config.root, p)));
let md;
const cache = /* @__PURE__ */ new Map();
return {
watch: pattern,
async load(files) {
if (!files) {
files = (await init.glob(pattern, {
ignore: ["**/node_modules/**", "**/dist/**"]
})).sort();
}
md = md || await init.createMarkdownRenderer(
config.srcDir,
config.markdown,
config.site.base,
config.logger
);
const raw = [];
for (const file of files) {
if (!file.endsWith(".md")) {
continue;
}
const timestamp = fs.statSync(file).mtimeMs;
const cached = cache.get(file);
if (cached && timestamp === cached.timestamp) {
raw.push(cached.data);
} else {
const src = fs.readFileSync(file, "utf-8");
const { data: frontmatter, excerpt } = init.matter(src, {
excerpt: true
});
const url = "/" + vite.normalizePath(path.relative(config.root, file)).replace(
/\.md$/,
config.cleanUrls ? "" : ".html"
);
const html = render ? md.render(src) : void 0;
const renderedExcerpt = renderExcerpt ? excerpt && md.render(excerpt) : void 0;
const data = {
src: includeSrc ? src : void 0,
html,
frontmatter,
excerpt: renderedExcerpt,
url
};
cache.set(file, { data, timestamp });
raw.push(data);
}
}
return transform ? transform(raw) : raw;
}
};
}
exports.ScaffoldThemeType = init.ScaffoldThemeType;
exports.build = init.build;
exports.createMarkdownRenderer = init.createMarkdownRenderer;
exports.createServer = init.createServer;
exports.defineConfig = init.defineConfig;
exports.defineConfigWithTheme = init.defineConfigWithTheme;
exports.defineLoader = init.defineLoader;
exports.init = init.init;
exports.resolveConfig = init.resolveConfig;
exports.resolvePages = init.resolvePages;
exports.resolveSiteData = init.resolveSiteData;
exports.resolveUserConfig = init.resolveUserConfig;
exports.scaffold = init.scaffold;
exports.serve = init.serve;
Object.defineProperty(exports, 'loadEnv', {
enumerable: true,
get: function () { return vite.loadEnv; }
});
exports.createContentLoader = createContentLoader;