基于 pandoc + netlify + github 搭建的文档平台。
从 .md 到 .html 文件渲染,非 .md 文件将原样输出。
|--source # 源文件目录
|----index.md
|----template.html # 模板文件
|--public # 发布目录
|----index.html
|--build.sh # 构建脚本
|--netlify.toml # 配置文件
source/index.md
---
title: "hello"
date: "2026-01-07 10:28:00"
---
hello world
source/template.html
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>$title$</title>
<meta name="date" content="$date$">
</head>
<body>
$body$
</body>
</html>
build.sh
#!/usr/bin/env bash
find ./source -type f | while read -r file; do
if [[ "$file" == *.md ]]; then
target_file=$(echo "$file" | sed 's/\.\/source\///' | sed 's/\.md$//')
pandoc "$file" --template=./source/template.html -o "./public/${target_file}.html"
else
target_file=$(echo "$file" | sed 's/\.\/source\///')
mkdir -p "$(dirname "./public/${target_file}")"
cp "$file" "./public/${target_file}"
fi
done
netlify.toml
[build]
command = "bash ./build.sh"
publish = "public"
[build.environment]
PANDOC_VERSION = "3.8.3"