rarst / wprss2hugo
WordPress eXtended RSS 到 Hugo 导入工具
0.2
2019-10-22 12:15 UTC
Requires
- php: >=7.3
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- league/html-to-markdown: ^4.8
- mnapoli/silly: ^1.7
- pimple/pimple: ^3.2
- prewk/xml-string-streamer: ^0.11.0
- symfony/filesystem: ^4.3
- symfony/yaml: ^4.3
- yosymfony/toml: ^1.0
Requires (Dev)
- pds/skeleton: ^1.0
This package is auto-updated.
Last update: 2024-08-25 19:17:20 UTC
README
Go 静态。Hugo 静态。
wprss2hugo 是一个从 WordPress eXtended RSS 导出格式到 Hugo 静态网站生成器的导入工具。
它旨在全面且合理灵活,但主要目的是降低我的托管费用。
安装
wprss2hugo 是一个 PHP 7.3+ 的命令行项目,使用 Composer 进行安装。
composer create-project rarst/wprss2hugo
使用
cd wprss2hugo
php bin/wprss2hugo.php example.WordPress.YYYY-MM-DD.xml
结果生成在 output
文件夹中。
注意: WordPress 可能不会存储和导出有效的 HTML 段落标记。您可能需要在导出之前将类似 add_filter( 'the_content_export', 'wpautop' );
的内容添加到 WP 安装中。
命令行参数
php bin/wprss2hugo.php --help Arguments: file Path to a WordPress export XML file. Options: --content-type= html|md [default: "html"] --front-matter-type= yaml|toml|json [default: "yaml"] --data-type= yaml|toml|json [default: "yaml"]
注意:文章内容的 Markdown 转换是尽力而为的,在复杂的标记上可能不太理想。
注意: TOML 格式不适用于数据,TOML 格式的数据文件将数据分配给一个虚拟的 data
根键。
数据映射
数据检索
附件
附件以 attachment
页面类型存储,可以通过父帖子 ID 检索。
{{ $attachments := where (where .Site.Pages "Type" "attachment") "Params.parentid" .Params.id }} {{ with $attachments }} <h2>Attachments</h2> {{ range . }} <img src="{{ .Params.attachmenturl }}" {{ with .Params.meta._wp_attachment_image_alt }}alt="{{ . }}"{{ end }} /> {{ end }} {{ end }}
评论
评论以数据文件的形式存储,可以通过父帖子 ID 检索。
{{ with .Site.Data.comments }} {{ with index . (string $.Page.Params.id) }} <h2>Comments</h2> <ul> {{ range sort . "id" }} <li>{{ .author }} says: {{ .content | safeHTML }}</li> {{ end }} </ul> {{ end }} {{ end }}