+
文章发布于 {{ postTime }},在 {{ postType }} 分类下。{{#if isBlogAdmin}} + 编辑此页。 + {{/if}}
+diff --git a/src/templates/oipress/article.js b/src/templates/oipress/article.js new file mode 100644 index 0000000..3610d8b --- /dev/null +++ b/src/templates/oipress/article.js @@ -0,0 +1,292 @@ +import Vue from 'vue' +import './common' +import { + initKatex, + initHighlight +} from 'scripts/article' +import ArticleVote from './layouts/article_vote.vue' +import ArticleComments from './layouts/article_comments.vue' +import $ from 'jquery' +import ArticleNav from './layouts/article_nav.vue' +import TOC from './layouts/toc.vue' +import Admonition from './layouts/admonition.vue' +import './styles/github.css' +import './styles/github_dark.css' +import './styles/article.css' + +BlogGlobals.luoguAddress = 'https://www.luogu.com.cn' +BlogGlobals.picAddress = 'https://cdn.luogu.com.cn' + +window.navBar = new Vue({ + el: '#nav-bar', + render: h => h(ArticleNav) +}) + +async function initHljs () { + // Function + $('pre code').each((_, block) => { + const classes = $(block)[0].className.split(' ') + let isHljs = false + for (let i = 0; i < classes.length; i++) { + const name = classes[i] + if (name === 'hljs') { + isHljs = true + } + const matchLang = name.match(/^language-(\w+)(\{[\d\-,]+\})?(\*?)$/) + if (!matchLang) { + continue + } + isHljs = true + classes[i] = 'language-' + matchLang[1] + if (matchLang[2] !== undefined) { + const res = matchLang[2].match(/\d+-\d+|\d+/g) + for (let i = 0; i < res.length; i++) { + const ps = res[i].split('-') + if (ps.length === 1) { + ps.push(ps[0]) + } + res[i] = ps + // add highlights here + } + $(block).parent().attr('line-highlights', JSON.stringify(res)) + } + if (matchLang[3] === '*') { + $(block).parent().attr('line-numbers', true) + } + } + if (isHljs) { + $(block).parent().attr('is-hljs', true) + } + $(block).attr('class', classes.join(' ')) + }) + await initHighlight() + $('pre').each((_, block) => { + if ($(block).attr('is-hljs') === undefined) { + return + } + const code = $(block).find('code') + const u = $('
') + $(block).append(u) + u.append(code) + const len = code.text().split('').reduce((prev, curr) => prev + (curr === '\n'), 0) + 1 + if ($(block).attr('line-numbers') !== undefined) { + u.prepend('文章发布于 {{ postTime }},在 {{ postType }} 分类下。{{#if isBlogAdmin}} + 编辑此页。 + {{/if}}
+{{ post.contentDescription }}
+