From 4cc7106e53485e9c1e7b2d043f99ba33b2f859ad Mon Sep 17 00:00:00 2001 From: Leon Ding Date: Mon, 1 Jul 2024 23:54:05 +0800 Subject: [PATCH] add: book builder output. --- .gitignore | 2 +- README.md | 12 ++- book/chapter_1.1.0.md | 4 +- book/chapter_1.1.1.md | 83 ++++++++++++++++ root.yml | 10 +- settings.yml | 5 +- src/book/builder.rs | 159 ++++++++++++++++++++++++------- src/book/root.rs | 7 -- src/book/settings.rs | 5 +- src/cli/args.rs | 5 +- src/cli/commands.rs | 22 +++-- src/html/hypertext.rs | 4 +- src/html/markdown.rs | 3 +- src/html/template.rs | 4 + src/main.rs | 12 +-- src/utils/logger.rs | 1 + tests/book/builder_test.rs | 15 ++- theme/typikon-theme/index.html | 168 +++------------------------------ 18 files changed, 290 insertions(+), 231 deletions(-) diff --git a/.gitignore b/.gitignore index c05cbb1..74b3714 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .DS_Store *.log /target - +docs cobertura.xml \ No newline at end of file diff --git a/README.md b/README.md index 0ca78fa..43f5312 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,29 @@ # Typikon -**Typikon lets you use markdown to write your online books.** +Typikon lets you use markdown to write your online books. --- ![https://img.shields.io/badge/Typikon-Rust%20CLI-brightgreen](https://img.shields.io/badge/📖%20Typikon-Rust%20🦀️-yellow) [![codecov](https://codecov.io/github/auula/typikon/branch/main/graph/badge.svg?token=FaR2OdNYeB)](https://codecov.io/github/auula/typikon) [![License](https://img.shields.io/badge/license-Apache-db5149.svg)](https://github.com/auula/typikon/blob/master/LICENSE) -![https://img.shields.io/github/repo-size/auula/typikon](https://img.shields.io/github/repo-size/auula/typikon) [![action](https://github.com/auula/typikon/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/auula/typikon/actions/workflows/rust.yml) +[![Twitter URL](https://img.shields.io/twitter/follow/auula_?style=social)](https://twitter.com/auula_) --- -A static website rendering tool similar to mdbook and hugo, but it focuses only on rendering markdown into an online book, and is easier to use than the other tools. +## Introduce + +Typikon name derived from [Typikon](https://en.wikipedia.org/wiki/Typikon) Book, the a static website rendering tool similar to mdbook and hugo, but it focuses only on rendering markdown into an online book, and is easier to use than the other tools. --- +## Preview +
Alt text Alt text
+ +--- \ No newline at end of file diff --git a/book/chapter_1.1.0.md b/book/chapter_1.1.0.md index 8c4c820..19d9838 100644 --- a/book/chapter_1.1.0.md +++ b/book/chapter_1.1.0.md @@ -1,4 +1,4 @@ -### MySQL 8.x 安装和配置 +### /book/chapter_1.1.0.md 在 MySQL 8.x 中引入了许多新特性和改进,包括 JSON 和 JavaScript 作为数据库查询语言,以及更好的性能和安全性。例如,在连接过程中出现的 `Public Key Retrieval is not allowed` 错误提示,这些都是新版本的特性。本文将记录在最新版本的 Ubuntu 中安装 MySQL 8.x 的完整过程。 @@ -64,7 +64,7 @@ flush privileges; - 子项目1 - 子项目2 -这是一个 [超链接测试]() 对文本内容。 +这是一个 [超链接测试](https://www.ibyte.me/) 对文本内容。 ## 插入普通图片 diff --git a/book/chapter_1.1.1.md b/book/chapter_1.1.1.md index e69de29..b2b9c2c 100644 --- a/book/chapter_1.1.1.md +++ b/book/chapter_1.1.1.md @@ -0,0 +1,83 @@ +### /book/chapter_1.1.1.md + +在 MySQL 8.x 中引入了许多新特性和改进,包括 JSON 和 JavaScript 作为数据库查询语言,以及更好的性能和安全性。例如,在连接过程中出现的 `Public Key Retrieval is not allowed` 错误提示,这些都是新版本的特性。本文将记录在最新版本的 Ubuntu 中安装 MySQL 8.x 的完整过程。 + +--- + +### 安装和配置 + +在安装 MySQL 8.x 之前,可以先更新操作系统和软件包: + +```sh +sudo apt update && apt upgrade -y +``` + +更新完成后,可以执行以下命令来查找和安装 MySQL 8.x 软件包: + +```sh +sudo apt search mysql +sudo apt install mysql-* +``` + +安装完成后,使用 `sudo mysql_secure_installation` 初始化 root 用户的密码: + +```sh +sudo mysql_secure_installation +``` + +如果需要允许远程用户访问 MySQL 服务器,可以修改配置文件 `/etc/mysql/mysql.conf.d/mysqld.cnf` 中的 `bind-address`,设置为 `0.0.0.0`: + +```ini +bind-address = 0.0.0.0 +mysqlx-bind-address = 127.0.0.1 +``` + +然后可以为远程用户授予访问权限: + +```sql +GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码' WITH GRANT OPTION; +``` + +--- + +### 解决安全连接问题 + +在 MySQL 8.x 中,如果出现 `Public Key Retrieval is not allowed` 错误提示,可以执行以下命令来解决: + +```sql +ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码'; +``` + +执行后,刷新授权表: + +```sql +flush privileges; +``` + +最后,请确保允许服务器上的 `3306` 端口连接。 + + +## 列表示例 + +- 项目1 +- 项目2 + - 子项目1 + - 子项目2 + +这是一个 [超链接测试](https://www.ibyte.me/) 对文本内容。 + +## 插入普通图片 + +![java](https://img.ibyte.me/470eor.jpg) + +## 引用示例 + +> 这是一个引用示例,可以包含多行文本和**加粗**文字。 + +## 表格示例 + +| 姓名 | 年龄 | 城市 | +|--------|------|--------| +| Alice | 25 | 北京 | +| Bob | 30 | 上海 | +| Carol | 28 | 广州 | diff --git a/root.yml b/root.yml index 17fec3b..f8cd73e 100644 --- a/root.yml +++ b/root.yml @@ -4,18 +4,16 @@ root: index: "index.md" chapters: - title: "Chapter 1" - path: "/chapter1" index: "/chapter1/chapter1.md" sub_chapters: - title: "Section 1.1" - path: "/chapter1/chapter1-section1.1.md" + path: "book/chapter_1.1.0.md" - title: "Section 1.2" - path: "/chapter1/chapter1-section1.2.md" + path: "book/chapter_1.1.1.md" - title: "Chapter 2" - path: "/chapter2" index: "/chapter2/chapter2.md" sub_chapters: - title: "Section 2.1" - path: "/chapter2/chapter2-section2.1.md" + path: "book/chapter_1.1.0.md" - title: "Section 2.2" - path: "/chapter2/chapter2-section2.2.md" + path: "book/chapter_1.1.1.md" diff --git a/settings.yml b/settings.yml index b575cb9..dc91bee 100644 --- a/settings.yml +++ b/settings.yml @@ -1,9 +1,10 @@ settings: about: - title: 现代 Java 编程指南 + title: Typikon Book author: Leon Ding - description: 一本基于 JDK21 版本讲解 Java21 新特性编程实践书籍,采用 WSL + VSCode 作为基础开发环境。 + description: Typikon name derived from Typikon Book, the a static website rendering tool similar to mdbook and hugo, but it focuses only on rendering markdown into an online book, and is easier to use than the other tools. language: zh-cn + keywords: typikon,book,website,generator,static,html,css,js,theme,rust directory: theme: theme diff --git a/src/book/builder.rs b/src/book/builder.rs index 617e406..59d568b 100644 --- a/src/book/builder.rs +++ b/src/book/builder.rs @@ -1,41 +1,78 @@ -use std::io; +use std::{collections::HashMap, fs, io, path::Path}; use tera::Tera; use crate::{ book, - html::{ - self, - template::{self, Template}, - }, + html::{self, template::Template, Hypertext, Markdown}, + utils::Logger, }; -use super::{get_settings, Root, Settings}; +use super::{Root, Settings}; #[derive(Debug)] pub struct Builder { root: Root, - pub templates: Template, pub engine: Tera, settings: Settings, + pub templates: Vec