No project description provided
Project description
Ugc tools
一个将mardown转换成为png的工具,特别适合于小红书发贴,也可定制为支持其他自媒体。
工作原理
将文案中固定部分提取为模板(html),创作内容部分使用markdown。
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
{css}
</style>
</head>
<body>
<div id="rb">
<div id="header">
<div id="date_extra">
<div id="date">{date:YYYY/MM/DD ddd}</div>
<div id="extra">{extra}</div>
</div>
<div id="title">一觉醒来财经圈发生了什么</div>
<div id="subtitle">
<div id="author">By {author}</div>
</div>
</div>
<div id="content">
{content}
</div>
</div>
</body>
</html>
content部分即为我们要创作的内容,格式为markdown。生成最终图像前,工具将其转化为html,再插入到{content} 所标识的位置处。
分页
使用来进行分页。
比如下面的markdown:
this is page 1
<!-- page-->
this is page2
将生成两张图片。
每一页都可以使用自己的模板。比如,第0页的模板名为page-0.tpl,第一页的模板为page-1.tpl。如果对应的模板不存在,则使用default.tpl。
语法
author
可以在cfg.json中定义author,然后可以将其插入到模板中。
date
可以在模板中使用 {date: formatDate}宏。系统将使用当前日期(也可通过命令行传入其它日期)。
extra
在模板中,允许插入一个自定义字段。该字段将通过命令行传入。
Usage
通过命令行:
ugc news markdown_file --extra "早间60秒" --serve
这将会生成png图片,并可通过http://ip:1086来预览。 支持的选项有: * --date '2023-03-31' * --serve: 这将开启一个http服务器,供预览生成的图片 * --extra: 向模板提供额外的信息
markdown_file只传文件名,不传路径。markdown_file的搜索路径在 cfg.json中指定。
配置
配置和模板文件在~/.ugc/redbook/news下。首次运行后,将自动生成该目录及示例文件。
自定义模式
样式中提供了 rb, header, title, date_extra, subtitle, re等带id的元素可供定制。
安装
需要通过conda安装weasyprint:
conda install weasyprint
然后安装:
pip install ugc-tools
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.