Skip to content

Commit

Permalink
docs: use vitepress
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegoo committed Aug 14, 2023
1 parent b80a808 commit db2facc
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
TARGET_REPO: imaegoo/twikoo
TARGET_BRANCH: gh-pages
BUILD_SCRIPT: cd docs && yarn && yarn docs:build
BUILD_DIR: .vuepress/dist
BUILD_DIR: .vitepress/dist
CNAME: twikoo.js.org
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ dist
# public

# vuepress build output
.vuepress/dist
docs/.vuepress/dist
docs/.vitepress/dist
docs/.vitepress/cache

# Serverless directories
.serverless/
Expand Down
54 changes: 54 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
locales: {
root: {
label: '简体中文',
lang: 'zh-CN',
title: 'Twikoo 文档',
description: 'Twikoo 文档',
themeConfig: {
sidebar: [
{ text: '简介', link: '/' },
{ text: '快速上手', link: '/quick-start' },
{ text: '常见问题', link: '/faq' },
{ text: 'API 文档', link: '/api' },
{ text: '相关文档', link: '/link' }
]
}
},
en: {
label: 'English (US)',
lang: 'en',
link: '/en/',
title: 'Twikoo Docs',
description: 'Twikoo Docs',
themeConfig: {
sidebar: [
{ text: 'Introduction', link: '/en/' },
{ text: 'Quick start', link: '/en/quick-start' },
{ text: 'FAQ', link: '/en/faq' },
{ text: 'API', link: '/en/api' }
]
}
}
},
themeConfig: {
search: {
provider: 'algolia',
options: {
appId: 'TM627WNO90',
apiKey: 'f81194a47bc4be7984df25fc480c60a7',
indexName: 'twikoo'
}
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/imaegoo/twikoo' }
],
editLink: {
pattern: 'https://github.com/imaegoo/twikoo/edit/main/docs/:path'
}
},
lastUpdated: true
})
81 changes: 81 additions & 0 deletions docs/.vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
const { Layout } = DefaultTheme
const envId = 'https://twikoo.vercel.app'
const twikooJs = ref(null)
const router = useRouter()
function initTwikoo () {
try {
twikoo.init({
envId,
onCommentLoaded: initLightGallery
})
} catch (e) {}
}
function initLightGallery () {
// This function is compiled to ES5
var commentContents = document.getElementsByClassName('tk-content');
for (var i = 0; i < commentContents.length; i++) {
var commentItem = commentContents[i];
var imgEls = commentItem.getElementsByTagName('img');
if (imgEls.length > 0) {
for (var j = 0; j < imgEls.length; j++) {
var imgEl = imgEls[j];
var aEl = document.createElement('a');
aEl.setAttribute('class', 'tk-lg-link');
aEl.setAttribute('href', imgEl.getAttribute('src'));
aEl.setAttribute('data-src', imgEl.getAttribute('src'));
aEl.appendChild(imgEl.cloneNode(false));
imgEl.parentNode.insertBefore(aEl, imgEl.nextSibling);
imgEl.remove();
}
lightGallery(commentItem, {
selector: '.tk-lg-link',
share: false
})
}
}
}
function initJs () {
if (twikooJs.value) {
twikooJs.value.onload = initTwikoo
router.onAfterRouteChanged = onRoute
}
}
function onRoute (to) {
if (to) setTimeout(initTwikoo, 1000)
}
onMounted(() => {
initTwikoo()
initJs()
})
</script>

<template>
<Layout>
<template #doc-after>
<div class="comment-container">
<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<component :is="'script'" defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></component>
<component :is="'script'" defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></component>

<!-- lightGallery -->
<link rel="stylesheet" href="https://cdn.staticfile.org/lightgallery/2.1.8/css/lightgallery.css">
<component :is="'script'" src="https://cdn.staticfile.org/lightgallery/2.1.8/lightgallery.min.js"></component>

<!-- Twikoo -->
<div id="twikoo"></div>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/twikoo.all.min.js" ref="twikooJs"></component>
</div>
</template>
</Layout>
</template>
9 changes: 9 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import DefaultTheme from 'vitepress/theme'
import Layout from './Layout.vue'

export default {
...DefaultTheme,
// override the Layout with a wrapper component that
// injects the slots
Layout
}
56 changes: 0 additions & 56 deletions docs/.vuepress/config.js

This file was deleted.

16 changes: 0 additions & 16 deletions docs/.vuepress/theme/index.js

This file was deleted.

81 changes: 0 additions & 81 deletions docs/.vuepress/theme/layouts/Layout.vue

This file was deleted.

26 changes: 21 additions & 5 deletions docs/en/README.md → docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

----

[![](https://img.shields.io/npm/v/twikoo)](https://www.npmjs.com/package/twikoo)
[![](https://img.shields.io/bundlephobia/minzip/twikoo)](https://bundlephobia.com/result?p=twikoo)
[![](https://img.shields.io/npm/dt/twikoo)](https://www.npmjs.com/package/twikoo)
[![](https://data.jsdelivr.com/v1/package/npm/twikoo/badge)](https://www.jsdelivr.com/package/npm/twikoo)
[![](https://img.shields.io/npm/l/twikoo)](https://github.com/imaegoo/twikoo/blob/main/LICENSE)
<style>
.shields {
display: inline-block;
}
</style>

<a href="https://www.npmjs.com/package/twikoo">
<img class="shields" src="https://img.shields.io/npm/v/twikoo" />&nbsp;
</a>
<a href="https://bundlephobia.com/result?p=twikoo">
<img class="shields" src="https://img.shields.io/bundlephobia/minzip/twikoo" />&nbsp;
</a>
<a href="https://www.npmjs.com/package/twikoo">
<img class="shields" src="https://img.shields.io/npm/dt/twikoo" />&nbsp;
</a>
<a href="https://www.jsdelivr.com/package/npm/twikoo">
<img class="shields" src="https://data.jsdelivr.com/v1/package/npm/twikoo/badge" />&nbsp;
</a>
<a href="https://github.com/imaegoo/twikoo/blob/main/LICENSE">
<img class="shields" src="https://img.shields.io/npm/l/twikoo" />
</a>

A **simple**, **safe**, **free** comment system.
[简体中文](/) | **English**
Expand Down
26 changes: 21 additions & 5 deletions docs/README.md → docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

----

[![](https://img.shields.io/npm/v/twikoo)](https://www.npmjs.com/package/twikoo)
[![](https://img.shields.io/bundlephobia/minzip/twikoo)](https://bundlephobia.com/result?p=twikoo)
[![](https://img.shields.io/npm/dt/twikoo)](https://www.npmjs.com/package/twikoo)
[![](https://data.jsdelivr.com/v1/package/npm/twikoo/badge)](https://www.jsdelivr.com/package/npm/twikoo)
[![](https://img.shields.io/npm/l/twikoo)](https://github.com/imaegoo/twikoo/blob/main/LICENSE)
<style>
.shields {
display: inline-block;
}
</style>

<a href="https://www.npmjs.com/package/twikoo">
<img class="shields" src="https://img.shields.io/npm/v/twikoo" />&nbsp;
</a>
<a href="https://bundlephobia.com/result?p=twikoo">
<img class="shields" src="https://img.shields.io/bundlephobia/minzip/twikoo" />&nbsp;
</a>
<a href="https://www.npmjs.com/package/twikoo">
<img class="shields" src="https://img.shields.io/npm/dt/twikoo" />&nbsp;
</a>
<a href="https://www.jsdelivr.com/package/npm/twikoo">
<img class="shields" src="https://data.jsdelivr.com/v1/package/npm/twikoo/badge" />&nbsp;
</a>
<a href="https://github.com/imaegoo/twikoo/blob/main/LICENSE">
<img class="shields" src="https://img.shields.io/npm/l/twikoo" />
</a>

一个简洁、安全、免费的静态网站评论系统。<br>
A simple, safe, free comment system.
Expand Down
Loading

0 comments on commit db2facc

Please sign in to comment.