temp
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
|
||||
pdf
|
||||
|
||||
.vitepress/cache
|
||||
.vitepress/dist
|
||||
21
.vitepress/config.mts
Normal file
21
.vitepress/config.mts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { defineConfig } from 'vitepress'
|
||||
import { homeSidebar } from './home.mts'
|
||||
// https://vitepress.dev/reference/site-config
|
||||
export default defineConfig({
|
||||
title: "AI 写书",
|
||||
description: "如果通过关键字进行写书,生成体系化知识库。",
|
||||
themeConfig: {
|
||||
// https://vitepress.dev/reference/default-theme-config
|
||||
nav: [
|
||||
{ text: '首页', link: '/' },
|
||||
],
|
||||
|
||||
sidebar: [
|
||||
...homeSidebar
|
||||
],
|
||||
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
|
||||
]
|
||||
}
|
||||
})
|
||||
4
.vitepress/home.mts
Normal file
4
.vitepress/home.mts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const homeSidebar = [
|
||||
{ text: '前言', link: '/preface' },
|
||||
{ text: '前言2', link: '/preface2' },
|
||||
]
|
||||
17
.vitepress/theme/index.ts
Normal file
17
.vitepress/theme/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
// https://vitepress.dev/guide/custom-theme
|
||||
import { h } from 'vue'
|
||||
import type { Theme } from 'vitepress'
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
import './style.css'
|
||||
import './print.css'
|
||||
export default {
|
||||
extends: DefaultTheme,
|
||||
Layout: () => {
|
||||
return h(DefaultTheme.Layout, null, {
|
||||
// https://vitepress.dev/guide/extending-default-theme#layout-slots
|
||||
})
|
||||
},
|
||||
enhanceApp({ app, router, siteData }) {
|
||||
// ...
|
||||
}
|
||||
} satisfies Theme
|
||||
17
.vitepress/theme/print.css
Normal file
17
.vitepress/theme/print.css
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
@media print {
|
||||
.VPLocalNav.has-sidebar,
|
||||
.VPDocFooter {
|
||||
display: none !important;
|
||||
}
|
||||
.VPButton.medium.brand {
|
||||
display: none !important;
|
||||
}
|
||||
.VPNavBarHamburger.hamburger {
|
||||
display: none !important;
|
||||
}
|
||||
.VPHome {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
}
|
||||
151
.vitepress/theme/style.css
Normal file
151
.vitepress/theme/style.css
Normal file
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Customize default theme styling by overriding CSS variables:
|
||||
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
||||
*/
|
||||
|
||||
/**
|
||||
* Colors
|
||||
*
|
||||
* Each colors have exact same color scale system with 3 levels of solid
|
||||
* colors with different brightness, and 1 soft color.
|
||||
*
|
||||
* - `XXX-1`: The most solid color used mainly for colored text. It must
|
||||
* satisfy the contrast ratio against when used on top of `XXX-soft`.
|
||||
*
|
||||
* - `XXX-2`: The color used mainly for hover state of the button.
|
||||
*
|
||||
* - `XXX-3`: The color for solid background, such as bg color of the button.
|
||||
* It must satisfy the contrast ratio with pure white (#ffffff) text on
|
||||
* top of it.
|
||||
*
|
||||
* - `XXX-soft`: The color used for subtle background such as custom container
|
||||
* or badges. It must satisfy the contrast ratio when putting `XXX-1` colors
|
||||
* on top of it.
|
||||
*
|
||||
* The soft color must be semi transparent alpha channel. This is crucial
|
||||
* because it allows adding multiple "soft" colors on top of each other
|
||||
* to create a accent, such as when having inline code block inside
|
||||
* custom containers.
|
||||
*
|
||||
* - `default`: The color used purely for subtle indication without any
|
||||
* special meanings attached to it such as bg color for menu hover state.
|
||||
*
|
||||
* - `brand`: Used for primary brand colors, such as link text, button with
|
||||
* brand theme, etc.
|
||||
*
|
||||
* - `tip`: Used to indicate useful information. The default theme uses the
|
||||
* brand color for this by default.
|
||||
*
|
||||
* - `warning`: Used to indicate warning to the users. Used in custom
|
||||
* container, badges, etc.
|
||||
*
|
||||
* - `danger`: Used to show error, or dangerous message to the users. Used
|
||||
* in custom container, badges, etc.
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-c-default-1: var(--vp-c-gray-1);
|
||||
--vp-c-default-2: var(--vp-c-gray-2);
|
||||
--vp-c-default-3: var(--vp-c-gray-3);
|
||||
--vp-c-default-soft: var(--vp-c-gray-soft);
|
||||
|
||||
--vp-c-brand-1: var(--vp-c-indigo-1);
|
||||
--vp-c-brand-2: var(--vp-c-indigo-2);
|
||||
--vp-c-brand-3: var(--vp-c-indigo-3);
|
||||
--vp-c-brand-soft: var(--vp-c-indigo-soft);
|
||||
|
||||
--vp-c-tip-1: var(--vp-c-brand-1);
|
||||
--vp-c-tip-2: var(--vp-c-brand-2);
|
||||
--vp-c-tip-3: var(--vp-c-brand-3);
|
||||
--vp-c-tip-soft: var(--vp-c-brand-soft);
|
||||
|
||||
--vp-c-warning-1: var(--vp-c-yellow-1);
|
||||
--vp-c-warning-2: var(--vp-c-yellow-2);
|
||||
--vp-c-warning-3: var(--vp-c-yellow-3);
|
||||
--vp-c-warning-soft: var(--vp-c-yellow-soft);
|
||||
|
||||
--vp-c-danger-1: var(--vp-c-red-1);
|
||||
--vp-c-danger-2: var(--vp-c-red-2);
|
||||
--vp-c-danger-3: var(--vp-c-red-3);
|
||||
--vp-c-danger-soft: var(--vp-c-red-soft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Button
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-button-brand-border: transparent;
|
||||
--vp-button-brand-text: var(--vp-c-white);
|
||||
--vp-button-brand-bg: var(--vp-c-brand-3);
|
||||
--vp-button-brand-hover-border: transparent;
|
||||
--vp-button-brand-hover-text: var(--vp-c-white);
|
||||
--vp-button-brand-hover-bg: var(--vp-c-brand-2);
|
||||
--vp-button-brand-active-border: transparent;
|
||||
--vp-button-brand-active-text: var(--vp-c-white);
|
||||
--vp-button-brand-active-bg: var(--vp-c-brand-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Home
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-home-hero-name-color: transparent;
|
||||
--vp-home-hero-name-background: -webkit-linear-gradient(120deg,
|
||||
#bd34fe 30%,
|
||||
#41d1ff);
|
||||
|
||||
--vp-home-hero-image-background-image: linear-gradient(-45deg,
|
||||
#bd34fe 50%,
|
||||
#47caff 50%);
|
||||
--vp-home-hero-image-filter: blur(44px);
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(56px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(68px);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Custom Block
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-custom-block-tip-border: transparent;
|
||||
--vp-custom-block-tip-text: var(--vp-c-text-1);
|
||||
--vp-custom-block-tip-bg: var(--vp-c-brand-soft);
|
||||
--vp-custom-block-tip-code-bg: var(--vp-c-brand-soft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Algolia
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
.DocSearch {
|
||||
--docsearch-primary-color: var(--vp-c-brand-1) !important;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* @media (min-width: 640px) {
|
||||
|
||||
.VPHomeHero .heading .text {
|
||||
max-width: 850px;
|
||||
}
|
||||
} */
|
||||
|
||||
.author {
|
||||
text-align: right;
|
||||
font-size: 14px;
|
||||
margin-top: 10px;
|
||||
color: var(--vp-c-text-2);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
49
api-examples.md
Normal file
49
api-examples.md
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# Runtime API Examples
|
||||
|
||||
This page demonstrates usage of some of the runtime APIs provided by VitePress.
|
||||
|
||||
The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files:
|
||||
|
||||
```md
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
|
||||
const { theme, page, frontmatter } = useData()
|
||||
</script>
|
||||
|
||||
## Results
|
||||
|
||||
### Theme Data
|
||||
<pre>{{ theme }}</pre>
|
||||
|
||||
### Page Data
|
||||
<pre>{{ page }}</pre>
|
||||
|
||||
### Page Frontmatter
|
||||
<pre>{{ frontmatter }}</pre>
|
||||
```
|
||||
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
|
||||
const { site, theme, page, frontmatter } = useData()
|
||||
</script>
|
||||
|
||||
## Results
|
||||
|
||||
### Theme Data
|
||||
<pre>{{ theme }}</pre>
|
||||
|
||||
### Page Data
|
||||
<pre>{{ page }}</pre>
|
||||
|
||||
### Page Frontmatter
|
||||
<pre>{{ frontmatter }}</pre>
|
||||
|
||||
## More
|
||||
|
||||
Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).
|
||||
27
index.md
Normal file
27
index.md
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# https://vitepress.dev/reference/default-theme-home-page
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: "AI 写书"
|
||||
text: "如果通过关键字进行写书,生成体系化知识库。"
|
||||
tagline: 用大模型写书是一项结合人工智能与人类创造力的高效创作方式
|
||||
actions:
|
||||
- theme: brand
|
||||
text: 开始阅读
|
||||
link: /preface
|
||||
# 你可以添加更多按钮
|
||||
|
||||
features:
|
||||
- title: 规划与设定
|
||||
details: 智能分析关键字,自动生成章节结构与知识体系,助力高效构思与内容框架搭建。
|
||||
- title: 内容生成与迭代
|
||||
details: 基于大模型,快速生成高质量文本,支持多轮优化与个性化调整,提升创作效率。
|
||||
- title: 编辑、润色
|
||||
details: AI辅助语法、风格、逻辑优化,自动检测错漏,协助打造专业、流畅的书稿。
|
||||
---
|
||||
|
||||
|
||||
<div class='author'>
|
||||
作者: 小熊猫呜呜呜
|
||||
</div>
|
||||
85
markdown-examples.md
Normal file
85
markdown-examples.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Markdown Extension Examples
|
||||
|
||||
This page demonstrates some of the built-in markdown extensions provided by VitePress.
|
||||
|
||||
## Syntax Highlighting
|
||||
|
||||
VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting:
|
||||
|
||||
**Input**
|
||||
|
||||
````md
|
||||
```js{4}
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
msg: 'Highlighted!'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
**Output**
|
||||
|
||||
```js{4}
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
msg: 'Highlighted!'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Custom Containers
|
||||
|
||||
**Input**
|
||||
|
||||
```md
|
||||
::: info
|
||||
This is an info box.
|
||||
:::
|
||||
|
||||
::: tip
|
||||
This is a tip.
|
||||
:::
|
||||
|
||||
::: warning
|
||||
This is a warning.
|
||||
:::
|
||||
|
||||
::: danger
|
||||
This is a dangerous warning.
|
||||
:::
|
||||
|
||||
::: details
|
||||
This is a details block.
|
||||
:::
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
::: info
|
||||
This is an info box.
|
||||
:::
|
||||
|
||||
::: tip
|
||||
This is a tip.
|
||||
:::
|
||||
|
||||
::: warning
|
||||
This is a warning.
|
||||
:::
|
||||
|
||||
::: danger
|
||||
This is a dangerous warning.
|
||||
:::
|
||||
|
||||
::: details
|
||||
This is a details block.
|
||||
:::
|
||||
|
||||
## More
|
||||
|
||||
Check out the documentation for the [full list of markdown extensions](https://vitepress.dev/guide/markdown).
|
||||
18
package.json
Normal file
18
package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"scripts": {
|
||||
"docs:dev": "vitepress dev",
|
||||
"docs:build": "vitepress build",
|
||||
"docs:preview": "vitepress preview",
|
||||
"dev": "pnpm docs:dev",
|
||||
"pub": "rsync -av --delete .vitepress/dist/ light:/var/www/book/look-good",
|
||||
"copy": "bun scripts/copy.ts",
|
||||
"build": "pnpm docs:build",
|
||||
"book": "bun scripts/export-pdf.ts && pnpm copy"
|
||||
},
|
||||
"devDependencies": {
|
||||
"pdf-lib": "^1.17.1",
|
||||
"puppeteer": "^24.23.0",
|
||||
"sharp": "^0.34.4",
|
||||
"vitepress": "^1.6.4"
|
||||
}
|
||||
}
|
||||
2697
pnpm-lock.yaml
generated
Normal file
2697
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
4
preface.md
Normal file
4
preface.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# 自序
|
||||
|
||||
|
||||
123
|
||||
2
public/robots.txt
Normal file
2
public/robots.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
9
readme.md
Normal file
9
readme.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# AI 写书
|
||||
|
||||
|
||||
### 使用vitepress进行挂载网页
|
||||
|
||||
```sh
|
||||
# 初始化
|
||||
pnpx vitepress init
|
||||
```
|
||||
16
scripts/copy.ts
Normal file
16
scripts/copy.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const targetDir = path.join('.vitepress', 'dist', 'pdf');
|
||||
const sourceFile = path.join('pdf', 'book.pdf');
|
||||
const targetFile = path.join(targetDir, 'book.pdf');
|
||||
|
||||
// 创建目标文件夹(如果不存在)
|
||||
if (!fs.existsSync(targetDir)) {
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 复制文件
|
||||
fs.copyFileSync(sourceFile, targetFile);
|
||||
|
||||
console.log('PDF 已复制到 .vitepress/dist/pdf/book.pdf');
|
||||
89
scripts/export-pdf.ts
Normal file
89
scripts/export-pdf.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import puppeteer from 'puppeteer';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
|
||||
async function exportPDF(): Promise<void> {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
|
||||
// 设置页面样式适应 PDF
|
||||
await page.setViewport({ width: 1200, height: 800 });
|
||||
|
||||
// const baseUrl = 'http://localhost:5173'; // VitePress 开发服务器地址
|
||||
const baseUrl = 'https://look-good.xiongxiao.me'; // VitePress 开发服务器生产地址
|
||||
const outputPath = path.resolve(process.cwd(), 'pdf');
|
||||
|
||||
if (!fs.existsSync(outputPath)) {
|
||||
fs.mkdirSync(outputPath);
|
||||
}
|
||||
|
||||
// 根据 sidebar 配置,导出的路径列表
|
||||
const routes: string[] = [
|
||||
'/',
|
||||
'/preface',
|
||||
'/self-introduction',
|
||||
'/book/0-1',
|
||||
'/book/01',
|
||||
'/book/02',
|
||||
'/book/03',
|
||||
'/book/0-2',
|
||||
'/book/04',
|
||||
'/book/05',
|
||||
'/book/06',
|
||||
'/book/07',
|
||||
'/book/08',
|
||||
'/book/09',
|
||||
'/book/0-3',
|
||||
'/book/10',
|
||||
'/book/11',
|
||||
'/book/12',
|
||||
'/appendix/a',
|
||||
'/appendix/b',
|
||||
'/appendix/c',
|
||||
'/appendix/d',
|
||||
'/appendix/e'
|
||||
];
|
||||
|
||||
const pdfFiles: string[] = [];
|
||||
|
||||
for (const route of routes) {
|
||||
const url = baseUrl + route;
|
||||
const fileName = route === '/' ? 'index' : route.slice(1).replace(/\//g, '_');
|
||||
const pdfPath = path.join(outputPath, `${fileName}.pdf`);
|
||||
console.log(`⏳ 正在生成: ${fileName}.pdf from ${url}`);
|
||||
await page.goto(url, { waitUntil: 'networkidle0' });
|
||||
|
||||
await page.pdf({
|
||||
path: pdfPath,
|
||||
format: 'A4',
|
||||
printBackground: true,
|
||||
margin: {
|
||||
top: '20mm',
|
||||
right: '20mm',
|
||||
bottom: '20mm',
|
||||
left: '20mm',
|
||||
},
|
||||
});
|
||||
|
||||
pdfFiles.push(pdfPath);
|
||||
console.log(`✅ 已生成: ${fileName}.pdf`);
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
// 合并所有 PDF
|
||||
const mergedPdf = await PDFDocument.create();
|
||||
for (const pdfFile of pdfFiles) {
|
||||
const pdfBytes = fs.readFileSync(pdfFile);
|
||||
const pdf = await PDFDocument.load(pdfBytes);
|
||||
const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
|
||||
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
||||
}
|
||||
const mergedPdfBytes = await mergedPdf.save();
|
||||
const bookPdfPath = path.join(outputPath, 'book.pdf');
|
||||
fs.writeFileSync(bookPdfPath, mergedPdfBytes);
|
||||
console.log(`🎉 已合并为: book.pdf`);
|
||||
}
|
||||
|
||||
exportPDF();
|
||||
41
scripts/picture.ts
Normal file
41
scripts/picture.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import sharp from 'sharp';
|
||||
|
||||
const root = path.join(process.cwd(), 'public','assets', 'daily');
|
||||
|
||||
// 获取 root 目录下的所有图片,然后把图片的大小调整小一点,在 500k-1M 之间,放回原名。
|
||||
const zipPicture = async (root: string) => {
|
||||
const files = fs.readdirSync(root);
|
||||
for (const file of files) {
|
||||
const filePath = path.join(root, file);
|
||||
const stat = fs.statSync(filePath);
|
||||
if (stat.isFile() && /\.(jpg|jpeg|png)$/i.test(file)) {
|
||||
let buffer = fs.readFileSync(filePath);
|
||||
let size = buffer.length;
|
||||
if (size > 1024 * 1024) { // 超过1M才压缩
|
||||
let quality = 80;
|
||||
let compressedBuffer;
|
||||
do {
|
||||
compressedBuffer = await sharp(buffer)
|
||||
.jpeg({ quality })
|
||||
.toBuffer();
|
||||
size = compressedBuffer.length;
|
||||
quality -= 10;
|
||||
} while (size > 1024 * 1024 && quality > 30);
|
||||
|
||||
if (size < 500 * 1024) {
|
||||
// 如果压缩后小于500k,适当提高质量
|
||||
quality += 5;
|
||||
compressedBuffer = await sharp(buffer)
|
||||
.jpeg({ quality })
|
||||
.toBuffer();
|
||||
}
|
||||
fs.writeFileSync(filePath, compressedBuffer);
|
||||
console.log(`${file} 压缩后大小: ${(compressedBuffer.length / 1024).toFixed(2)} KB`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
zipPicture(root);
|
||||
Reference in New Issue
Block a user