-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,4 @@ EJS 模版语言的用法请参考 [EJS 文档](https://www.ejs.co/ "EJS" "_blan | |
|
||
将渲染出来 | ||
|
||
``` | ||
PageForge | ||
``` | ||
<%= pageData.title %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const {getPagePath, appendHtml, getRelativeBasePath} = require("./utils"); | ||
|
||
class PageDataProcessor { | ||
constructor(config, pages) { | ||
this.config = config; | ||
this.pages = pages; | ||
} | ||
|
||
/** | ||
* 构建基础页面数据 | ||
* @param {Object} metadata - 页面元数据 | ||
* @param {string} content - 页面内容 | ||
* @param {string} relativePath - 相对路径 | ||
* @param {string} locale - 语言代码 | ||
* @param {Object} gitInfo - Git信息 | ||
* @returns {Object} 处理后的页面数据 | ||
*/ | ||
buildBasePageData(metadata, content, relativePath, locale, gitInfo) { | ||
const forwardPath = this.getPath(relativePath, locale); | ||
|
||
return { | ||
pageData: { | ||
config: metadata.config, | ||
toc: metadata.toc, | ||
content: content, | ||
basePath: getRelativeBasePath(relativePath), | ||
layout: metadata.layout || 'layouts/content', | ||
gitInfo, | ||
...metadata, | ||
...forwardPath | ||
}, | ||
siteData: { | ||
nav: this.config.nav, | ||
...this.config | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* 构建布局页面数据 | ||
* @param {Object} metadata - 页面元数据 | ||
* @param {string} locale - 语言代码 | ||
* @returns {Object} 处理后的布局页面数据 | ||
*/ | ||
buildLayoutPageData(metadata, locale) { | ||
return { | ||
pageData: { | ||
config: metadata.config, | ||
basePath: getRelativeBasePath('/'), | ||
...metadata | ||
}, | ||
siteData: { | ||
nav: this.config.nav, | ||
...this.config | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* 获取页面路径信息 | ||
* @private | ||
*/ | ||
getPath(relativePath, locale) { | ||
const pagePath = getPagePath(relativePath); | ||
const localPath = appendHtml(pagePath, this.config, locale); | ||
const noLocalePath = this.config.feature?.i18n?.enable | ||
? localPath.replace(`/${locale}`, '') | ||
: localPath; | ||
|
||
return { | ||
localPath, | ||
noLocalePath, | ||
relativePath: relativePath.replace(locale, '') | ||
}; | ||
} | ||
} | ||
|
||
module.exports = PageDataProcessor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters