我的磨即时预览功能代码——特别感谢壮壮
2019-07-26 04:39:44 -0400
~version: "2.1"
title://h2
body://div[has-class("wo-main-body")]
# debug
#@debug: //img[ends-with(@data-src, ".png")]
# 1.设置可以使用IV的文章
# 由于我文章 URL 的命名是带有日期的,所以利用正则匹配下,以下规则只对该路径下的文章有效
?path: /\d+/.+
# 2.设置文章主体、标题、作者等信息
# body 为文章主体,我设置为原网页中第一个
下的内容
body: (//article)[1]
$header: $body//header
# 设置文章标题
title: $header//h1
# 设置文章作者和作者链接
# 根据自己网站上文章作者所在的标签设置
author: $header//div[@class="meta"]/span[@class="author"]
# 设置作者链接,设置为以 author 名为 Telegram username 的链接
@set_attr(href,"https://t.me/",$author): $author
author_url: $author/@href
# 设置站点名字
site_name: "中国信息化战略官方网站"
# 频道信息
channel: "@VIPN888888"
# 设置发布日期
published_date: $header//div[@class="meta"]/time/@datetime
# 3.处理文章图片
# 删除无效图片
@remove: $body//a//img[@data-src="//"]
# 将和标签下的
标签替换为,使子标签下的
正常显示
@replace_tag(): //a[.//img]
@replace_tag(): //p[.//img]
# 设置
标签的属性 src=data-src,这是因为我博客里面的图片时懒加载,没有实际的 src 属性
# 所以设置一个新属性 src,属性值与 data-src 相同
@set_attr(src,@data-src): $body//img
# 4.处理背景
# 如果存在$body//figure[@class="image featured"]//img,那么设置其为 cover
@if( $body//figure[@class="image featured"]//img ) {
cover: $body//figure[.//img]
}
# 设置链接预览时显示的图片,依次查询
image_url: $cover/self::img/@src
image_url: $cover/self::figure//img/@src
image_url: //head/meta[@property="og:image"]/@content
# 5.cleanup
# 去除原文章中 和
Back to home
Subscribe |
Register |
Login
| N