plan for ssg
This commit is contained in:
1 parent
a8867be72c
commit
fb69b2710f
73 files changed
+921
-718
No files matched your search
@@ -3,10 +3,9 @@ import crypto from 'crypto'
|
||||
import scopeCss from '@patarapolw/scope-css'
|
||||
import cheerio from 'cheerio'
|
||||
import ejs from 'ejs'
|
||||
import jieba from 'nodejieba'
|
||||
import showdown from 'showdown'
|
||||
|
||||
export class MakeHTML {
|
||||
export class MakeHtml {
|
||||
$ = cheerio.load('')
|
||||
|
||||
mdConverter = new showdown.Converter({
|
||||
@@ -18,7 +17,7 @@ export class MakeHTML {
|
||||
tables: true,
|
||||
tasklists: true,
|
||||
// simpleLineBreaks: true,
|
||||
openLinksInNewWindow: true,
|
||||
// openLinksInNewWindow: true,
|
||||
backslashEscapesHTMLTags: true,
|
||||
emoji: true,
|
||||
underline: true,
|
||||
@@ -72,9 +71,8 @@ export class MakeHTML {
|
||||
async parse(
|
||||
filename: string
|
||||
): Promise<{
|
||||
$: cheerio.Cheerio
|
||||
html(): string
|
||||
clean(): string
|
||||
html: string
|
||||
text: string
|
||||
}> {
|
||||
const id =
|
||||
'md-' +
|
||||
@@ -87,6 +85,7 @@ export class MakeHTML {
|
||||
|
||||
const $div = this.$(`<div id="${id}">`)
|
||||
$div.html(await this.getHTML(filename))
|
||||
|
||||
$div.find('style').each((_, el) => {
|
||||
const $el = this.$(el)
|
||||
const html = $el.html() || ''
|
||||
@@ -95,14 +94,21 @@ export class MakeHTML {
|
||||
}
|
||||
})
|
||||
|
||||
$div.find('a').each((_, el) => {
|
||||
const $el = this.$(el)
|
||||
const href = $el.attr('href') || ''
|
||||
|
||||
if (/^https?:\/\//.test(href)) {
|
||||
$el.attr({
|
||||
rel: 'noopener',
|
||||
target: '_blank',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
$: $div,
|
||||
html: () => {
|
||||
return this.$('<div>').append($div).html() || ''
|
||||
},
|
||||
clean: () => {
|
||||
return jieba.cutForSearch($div.text() || '').join(' ')
|
||||
},
|
||||
html: this.$('<div>').append($div).html() || '',
|
||||
text: $div.text(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user