Skip to content

Commit

Permalink
feat: replace prismjs with shiki
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Sep 9, 2023
1 parent e93cf8e commit ab2b51f
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 479 deletions.
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,10 @@ footer_links:
- title: Friends # link of friends mode / 友链模式
mode: 'links'

#! ---------------------------------------------------------------
#! Highlighter Shiki
#! ---------------------------------------------------------------
shiki:
enable: true
backgroundColor: "#1a1a1a"

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"script-ext-html-webpack-plugin": "^2.1.5",
"semantic-release": "^21.1.1",
"tailwindcss": "3.3.3",
"typescript": "~5.2.2",
"typescript": "^5.1.0",
"vite": "^4.4.9",
"vite-plugin-html-transformer": "^4.0.0",
"vite-plugin-pages": "^0.31.0",
Expand Down
8 changes: 4 additions & 4 deletions src/components/PageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,26 @@
</template>

<script lang="ts">
import '@/styles/prism-aurora-future.css'
import {
Ref,
computed,
defineComponent,
nextTick,
onMounted,
onUnmounted,
Ref,
ref,
toRefs,
watch
} from 'vue'
import { useI18n } from 'vue-i18n'
import { Sidebar, Toc, Profile } from '@/components/Sidebar'
import { Profile, Sidebar, Toc } from '@/components/Sidebar'
import { useCommonStore } from '@/stores/common'
import { useRoute } from 'vue-router'
import PostStats from './Post/PostStats.vue'
import { useAppStore } from '@/stores/app'
import useCommentPlugin from '@/hooks/useCommentPlugin'
import useLightBox from '@/hooks/useLightBox'
import ObSkeleton from '@/components/LoadingSkeleton/Skeleton.vue'
interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
getCommentCount(): void
Expand All @@ -101,7 +101,7 @@ interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
export default defineComponent({
name: 'ObPageContent',
components: { Sidebar, Toc, Profile, PostStats },
components: { ObSkeleton, Sidebar, Toc, Profile, PostStats },
props: {
post: {
type: Object,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ToggleSwitch/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default defineComponent({
},
emits: ['changeStatus'],
setup(props, { emit }) {
let { status } = toRefs(props)
const { status } = toRefs(props)
onMounted(() => {
changeTransform()
})
let toggleStyle = reactive({
const toggleStyle = reactive({
transform: '',
background: '#6e40c9'
})
Expand Down
6 changes: 1 addition & 5 deletions src/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import Breadcrumbs from '@/components/Breadcrumbs.vue'
import { useI18n } from 'vue-i18n'
import usePageTitle from '@/hooks/usePageTitle'
declare const Prism: any
export default defineComponent({
name: 'About',
name: 'ARAbout',
components: { PageContent, Breadcrumbs },
setup() {
const articleStore = useArticleStore()
Expand All @@ -29,8 +27,6 @@ export default defineComponent({
pageData.value = await articleStore.fetchArticle('about')
updateTitle()
await nextTick()
Prism.highlightAll()
}
onMounted(fetchArticle)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import usePageTitle from '@/hooks/usePageTitle'
import Sticky from '@/components/Sticky.vue'
export default defineComponent({
name: 'Home',
name: 'ARHome',
components: {
Feature,
FeatureList,
Expand Down
27 changes: 8 additions & 19 deletions src/pages/links.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
@on-apply-clicked="jumpToContent()"
/>

<template v-if="pageData.categoryMode === true">
<LinkCategoryList :links="(pageData.data as Record<string, Link[]>)" />
<template v-if="pageData.categoryMode">
<LinkCategoryList :links="pageData.data as Record<string, Link[]>" />
</template>

<template v-else>
<LinkList :links="(pageData.data as Link[])" />
<LinkList :links="pageData.data as Link[]" />
</template>

<div class="mt-8" id="content">
Expand Down Expand Up @@ -94,22 +94,12 @@
</template>

<script lang="ts">
import '@/styles/prism-aurora-future.css'
import {
Ref,
computed,
defineComponent,
nextTick,
onMounted,
ref,
watch
} from 'vue'
import { computed, defineComponent, nextTick, onMounted, Ref, ref } from 'vue'
import PostStats from '@/components/Post/PostStats.vue'
import LinkBox from '@/components/Link/LinkBox.vue'
import LinkCard from '@/components/Link/LinkCard.vue'
import { Page } from '@/models/Article.class'
import { Link, Page } from '@/models/Article.class'
import { Title } from '@/components/Title'
import { Link } from '@/models/Article.class'
import { useAppStore } from '@/stores/app'
import { useArticleStore } from '@/stores/article'
import { useI18n } from 'vue-i18n'
Expand All @@ -121,17 +111,17 @@ import Breadcrumbs from '@/components/Breadcrumbs.vue'
import usePageTitle from '@/hooks/usePageTitle'
import useJumpToEle from '@/hooks/useJumpToEle'
import useCommentPlugin from '@/hooks/useCommentPlugin'
import ObSkeleton from '@/components/LoadingSkeleton/Skeleton.vue'
interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
getCommentCount(): void
getPostView(): void
}
declare const Prism: any
export default defineComponent({
name: 'Links',
name: 'ARLinks',
components: {
ObSkeleton,
PostStats,
LinkBox,
LinkCard,
Expand All @@ -158,7 +148,6 @@ export default defineComponent({
await nextTick()
postStatsRef.value?.getCommentCount()
postStatsRef.value?.getPostView()
Prism.highlightAll()
}
const jumpToContent = () => {
Expand Down
6 changes: 1 addition & 5 deletions src/pages/page/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ import Comment from '@/components/Comment.vue'
import useCommentPlugin from '@/hooks/useCommentPlugin'
import { Locales } from '@/models/ThemeConfig.class'
declare const Prism: any
export default defineComponent({
name: 'Page',
name: 'ARPage',
components: { PageContent, Breadcrumbs, Comment },
setup() {
const articleStore = useArticleStore()
Expand All @@ -59,8 +57,6 @@ export default defineComponent({
pageData.value = response
pageTitle.value = response.title
updateTitle(appStore.locale)
await nextTick()
Prism.highlightAll()
}
const updateTitle = (locale?: Locales) => {
Expand Down
6 changes: 1 addition & 5 deletions src/pages/post/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
</template>

<script lang="ts">
import '@/styles/prism-aurora-future.css'
import { Sidebar, Toc, Profile } from '@/components/Sidebar'
import { Post } from '@/models/Post.class'
import { usePostStore } from '@/stores/post'
Expand All @@ -200,10 +199,8 @@ interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
getPostView(): void
}
declare const Prism: any
export default defineComponent({
name: 'ObPost',
name: 'ARPost',
components: {
Sidebar,
Toc,
Expand Down Expand Up @@ -256,7 +253,6 @@ export default defineComponent({
initializeLightBox()
postStatsRef.value?.getCommentCount()
postStatsRef.value?.getPostView()
Prism.highlightAll()
}
watch(
Expand Down
39 changes: 36 additions & 3 deletions src/styles/components/article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,30 @@
overflow-wrap: normal !important;
}

pre::-webkit-scrollbar {
width: 0.5em;
height: 0.5em;
}

pre::-webkit-scrollbar-track {
background-color: transparent;
border-radius: 0;
}

pre::-webkit-scrollbar-thumb {
background-color: var(--background-secondary);
border-radius: 0.5em;
box-shadow: inset 2px 2px 2px hsl(0deg 0% 100% / 25%), inset -2px -2px 2px rgb(0 0 0 / 25%);
}

pre code {
@apply inline-block;
padding: 0;
}

code:not([class^="language-"]) {
color: var(--text-normal);
p code {
margin: 0;
font-size: 0.85em;
border-radius: 3px;
overflow-wrap: break-word;
background-color: var(--bg-accent-05);
word-wrap: break-word;
Expand All @@ -652,6 +667,24 @@
}
}

div[class^="language-"] {
@apply relative rounded-2xl overflow-hidden shadow my-6;
}

div[class^="language-"] .lang,
div[class^="language-"] button,
{
@apply absolute top-4 right-5 z-50 opacity-40 capitalize;
}

div[class^="language-"] pre {
@apply py-4 relative;
}

div[class^="language-"] pre code {
@apply px-4 relative block;
}

.post-header {
@apply mb-4 px-4;
.post-labels {
Expand Down

0 comments on commit ab2b51f

Please sign in to comment.