Skip to content

Instantly share code, notes, and snippets.

@Gowee
Last active September 30, 2021 08:21
Show Gist options
  • Save Gowee/17421bd0cd36aa89dd2b7fdfd56bc10f to your computer and use it in GitHub Desktop.
Save Gowee/17421bd0cd36aa89dd2b7fdfd56bc10f to your computer and use it in GitHub Desktop.
The Telegram InstantView template rule for OpeningSource.org
# Maintained by: Hung-I WANG <whygowe@gmail.com>
~version: "2.1"
# e.g. `/1234`, `/1234/zh-tw`
?path: /\d+/(\w+/)?
# # The Telegram IV parser treats the webpage incorrectly, which results in mal-structured HTML/XML. Here try to fix it by rewrapping <meta> into <head> and moving them to the front of <body>.
# @prepend("<head>"): /html
# @prepend_to($@): //meta
# Overwrite the default author data hence it is not corret/proper.
author: //a[@rel="author"]/text()
author_url: //a[@rel="author"]/@href
channel: @OpeningSourceOrg
body: //div[contains(@class, "post-content")]
# Reformat tag list
@before(<hr>): $body//div[has-class("post-tags")]
@prepend("Tags: "): $body//div[has-class("post-tags")]
@before("#"): $body//div[has-class("post-tags")]/span/a
@after(" "): $body//div[has-class("post-tags")]/span
@wrap("<u>"): $body//div[has-class("post-tags")]/span/a
# Pull the footer copyright from otherwhere ouside the body
@append_to($body): //div[has-class("post-copyright")]
@replace_tag("<em>"): $body//div[has-class("post-copyright")]
@wrap("<p>"): $@
# Generate `figure>img` by copying and manipulate `meta[property="og:image"]` and take it as the cover.
@clone: (/html/head/meta[@property="og:image"])[0]
@replace_tag("<img>"): $@
@before_el(//article): $@
$temp: $@
@set_attr("src", @content): $@
@wrap("<figure>"): $temp
cover: $@
# To fix: Element <img> is not supported in <a>
# From: https://stackoverflow.com/questions/55076621/element-img-is-not-supported-in-a
@split_parent: //a/img
@split_parent: //p/img
@split_parent: //figure/table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment