Skip to content

Commit

Permalink
支持 code 和 inline 解析
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ committed Dec 29, 2024
1 parent 3c75199 commit 4010499
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 10 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/pageforge-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ dev ]

jobs:
test:
test-command:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -60,20 +60,21 @@ jobs:
- name: Test init command
run: |
cd test-sites/site1
mkdir -p test-sites/site2
cd test-sites/site2
pageforge init
- name: Test build command
run: |
mkdir -p test-sites/site2
cd test-sites/site2
mkdir -p test-sites/site3
cd test-sites/site3
pageforge create-site .
pageforge build
- name: Test serve command
run: |
mkdir -p test-sites/site3
cd test-sites/site3
mkdir -p test-sites/site4
cd test-sites/site4
pageforge create-site .
pageforge build
timeout 30s pageforge serve --port 3001 &
Expand Down
33 changes: 33 additions & 0 deletions docs/content/docs/create-site.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: 创建你的网站
---

安装 PageForge 后,你可以使用它来创建你的网站。您需要跳转到需要创建网站的文件夹,该文件夹必须是一个空文件夹。然后,您可以使用 PageForge 的命令行工具来创建网站。

我们假设您的文件夹是 `my-website`

```bash
pageforge init
```

或者

```bash
pageforge create-site .
```

或者指定文件夹路径

```bash
pageforge create-site my-website
```

安装完成后,它将是如下目录结构:

```
├── content
│   └── index.md
└── pageforge.yaml
```

然后,您可以使用 `pageforge build` 命令来构建网站,或者使用 `pageforge serve` 命令来预览网站。
4 changes: 4 additions & 0 deletions docs/content/docs/get-started.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: 快速上手
---

PageForge 是一款现代化的静态页面生成与部署平台,旨在帮助用户快速创建精美的静态网站,并一键部署到 GitHub Pages。 无论是个人博客、项目文档还是企业官网,PageForge 都能让你轻松实现高效构建、智能部署和即时上线。

PageForge 的使用过程非常简单,只需几步即可完成网站的构建、部署。你只需要编写 markdown 文件,PageForge 会帮你生成高质量的静态网站。无论是个人博客、项目文档还是企业官网,PageForge 都能让你轻松实现高效构建、智能部署和即时上线。
Expand Down
6 changes: 4 additions & 2 deletions docs/pageforge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ nav:

sidebar:
default:
- text: '安装 & 部署'
link: '/docs/get-started'
- text: 快速上手
link: '/docs/get-started'
- text: 创建你的网站
link: '/docs/create-site'
39 changes: 39 additions & 0 deletions lib/extension/marked/pageforge-inline-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const {marked} = require("marked");
const {loadComponent} = require("../../component-loader");

const PageForgeCodeExtension = {
name: 'pageforgeCode',
level: 'inline',
start(src) {
return src.match(/.*`/)?.index; // 匹配任何以反引号结尾的内容
},
tokenizer(src, tokens) {
// 匹配格式:任何文本 + `代码` + 任何文本,直到行尾或下一个反引号
const rule = /(.*?)`([^`]+)`([^`\n]*)/;
const match = rule.exec(src);

if (match && !src.startsWith('```')) {
return {
type: 'pageforgeCode',
raw: match[0],
prefix: match[1], // 代码前的文本
text: match[2], // 代码内容
suffix: match[3], // 代码后的文本
tokens: []
};
}
return false;
},
renderer(item) {
return item.prefix + loadComponent('code', {text: item.text}) + item.suffix;
}
};

marked.use({
extensions: [
PageForgeCodeExtension
],
breaks: true
});

module.exports = PageForgeCodeExtension;
12 changes: 10 additions & 2 deletions lib/extension/marked/pageforge-marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {marked} = require("marked");
const {loadComponent} = require('../../component-loader');
const PageForgeImageExtension = require('./pageforge-image');
const PageForgeLinkExtension = require('./pageforge-link');
const PageForgeInlineCodeExtension = require('./pageforge-inline-code');

const renderer = {
paragraph({tokens}) {
Expand Down Expand Up @@ -40,15 +41,22 @@ const renderer = {
return loadComponent('image', {
item
});
},
codespan(item) {
return loadComponent('code', {
text: item.text
});
}
};

marked.use({
extensions: [
PageForgeImageExtension,
PageForgeLinkExtension
PageForgeLinkExtension,
PageForgeInlineCodeExtension
],
renderer
renderer,
breaks: false
});

module.exports = marked;
7 changes: 7 additions & 0 deletions templates/components/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function template(item) {
return `
<code class="bg-gray-100 text-gray-900 px-1.5 py-0.5 rounded text-sm font-mono inline">
${item.text}
</code>
`;
};

0 comments on commit 4010499

Please sign in to comment.