diff --git a/_posts/2020/03/zhlevel-level-1.md b/_posts/2020/03/zhlevel-level-1.md index f4f5695..56317e5 100644 --- a/_posts/2020/03/zhlevel-level-1.md +++ b/_posts/2020/03/zhlevel-level-1.md @@ -7,12 +7,12 @@ tag: Comes from my old repository [here](https://github.com/patarapolw/zhlevel/blob/master/resources/level/hanzi.json). - +<%- xCard({ + href: "https://github.com/patarapolw/zhlevel/blob/master/resources/level/hanzi.json", + image: "https://avatars3.githubusercontent.com/u/21255931?s=400&v=4", + title: "patarapolw/zhlevel", + description: "Learn Chinese from sentences, Tatoeba, or use your own sentences - patarapolw/zhlevel - /resources/level/hanzi.json" +})%> Level One @@ -47,11 +47,11 @@ Level One According to - +<%- xCard({ + href: 'https://github.com/patarapolw/zhlevel/blob/master/resources/level/hsk.yaml', + image: 'https://avatars3.githubusercontent.com/u/21255931?s=400&v=4', + title: 'patarapaolw/zhlevel', + description: 'Learn Chinese from sentences, Tatoeba, or use your own sentences - patarapolw/zhlevel - /resources/level/hsk.yaml' +}) %> 爱, 八, 爸爸, 杯子, 北京, 本, 不, 不客气, 菜, 茶, 吃, 出租车, 打电话, 大, 的, 点, 电脑, 电视, 电影, 东西, 都, 读, 对不起, 多, 多少, 儿子, 二, 饭店, 飞机, 分钟 diff --git a/packages/nuxt/scripts/make-html.ts b/packages/nuxt/scripts/make-html.ts index 3efe32e..4f3ad52 100644 --- a/packages/nuxt/scripts/make-html.ts +++ b/packages/nuxt/scripts/make-html.ts @@ -37,6 +37,26 @@ export class MakeHTML { }, 'underscore-italic' ) + + /** + * ! This is the only way to preserve syntax highlighting, while output multiline strings correctly + */ + this.mdConverter.addExtension( + { + type: 'lang', + regex: /(^|\n)```html parsed([^]+)\n```\n/g, + replace: (_: string, p1: string, p2: string) => { + return ( + p1 + + ejs.render(p2, { + rmWhitespace: true, + beautify: false, + }) + ) + }, + }, + 'html-parsed' + ) } async parse( @@ -80,16 +100,36 @@ export class MakeHTML { return this.mdConverter.makeHtml( await ejs.renderFile(filename, { youtube: (id: string) => + ejs.render( + /* html */ ` + + + `, + { rmWhitespace: true, beautify: false } + ), + xCard: (opts: { + href: string + image?: string + title: string + description?: string + }) => this.$('') - .html( - /* html */ ` - - - ` + .append( + this.$('') + .attr(opts) + .append( + this.$('') + .attr({ + href: opts.href, + rel: 'noopener', + target: '_blank', + }) + .text(opts.title) + ) ) .html(), })