Skip to content

Commit

Permalink
chore: modify theme config api
Browse files Browse the repository at this point in the history
  • Loading branch information
Renovamen committed Feb 2, 2021
1 parent 52c3641 commit 13e5b37
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 73 deletions.
78 changes: 30 additions & 48 deletions example/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ module.exports = {
],
theme: 'gungnir',
themeConfig: {
search: true,
searchMaxSuggestions: 10,
searchPlaceholder: "$ grep ...",
author: "Gungnir",
authorAvatar: "/img/avatar.jpeg",
smoothScroll: true,
sidebarDepth: 5,
repo: 'Renovamen/vuepress-theme-gungnir',
docsDir: 'blog',
docsDir: 'example',
editLinks: true,
editLinkText: 'Edit this page on GitHub',
lastUpdated: "Last Updated",
codeTheme: "gungnir-dark",
hitokoto: true, // Enable hitokoto (一言) or not?
comment: true, // Enable comment system or not?
rss: true, // Enable RSS or not?
rss: {
site_url: 'https://vuepress-theme-gungnir.vercel.app',
copyright: 'Renovamen 2018-2021',
count: 20
},
comment: {
owner: 'This-is-an-Apple',
repo: 'gitalk-comments',
clientId: 'd6247712dc288a5a60ca',
clientSecret: 'ed1ec72417828343c79ed910a1b77d140fa715a7'
},
analytics: {
ga: 'UA-146858305-4',
ba: '0958eaa31f4f4656f36bd33673332939'
},
nav: [
{
text: 'Home',
Expand Down Expand Up @@ -57,17 +62,20 @@ module.exports = {
}
]
},
SNS: {
"github": "Renovamen",
"linkedin": "xiaohan-zou-55bba0160",
"facebook": "renovamen.zou",
"twitter": "renovamen_zxh",
"zhihu": "chao-neng-gui-su",
"email": "renovamenzxh@gmail.com",
personalInfo: {
name: "Gungnir",
avatar: "/img/avatar.jpeg",
description: 'A blog theme for VuePress.',
sns: {
"github": "Renovamen",
"linkedin": "xiaohan-zou-55bba0160",
"facebook": "renovamen.zou",
"twitter": "renovamen_zxh",
"zhihu": "chao-neng-gui-su",
"email": "renovamenzxh@gmail.com",
}
},
tagline: "A blog theme for VuePress.",
heroImage: "/hero.png",
bgImage: [
homeHeaderImages: [
{
"path": "/img/home-bg/1.jpg",
"mask": "rgba(40, 57, 101, .4)"
Expand All @@ -85,7 +93,7 @@ module.exports = {
"mask": "rgba(19, 75, 50, .2)"
}
],
pageConfig: {
pages: {
tags: {
title: 'Tags',
subtitle: 'Black Sheep Wall',
Expand All @@ -111,32 +119,6 @@ module.exports = {
`
},
plugins: [
[
'@vssue/vuepress-plugin-vssue', {
platform: 'github',
owner: 'This-is-an-Apple',
repo: 'gitalk-comments',
clientId: 'd6247712dc288a5a60ca',
clientSecret: 'ed1ec72417828343c79ed910a1b77d140fa715a7',
}
],
[
'@vuepress/google-analytics', {
'ga': 'UA-146858305-4'
}
],
[
'@renovamen/vuepress-plugin-baidu-tongji', {
'ba': '0958eaa31f4f4656f36bd33673332939'
}
],
[
'@renovamen/vuepress-plugin-rss', {
site_url: 'https://vuepress-theme-gungnir.vercel.app',
copyright: 'Renovamen 2018-2021',
count: 20
}
],
[
'@renovamen/vuepress-plugin-md-plus', {
all: true
Expand Down
4 changes: 2 additions & 2 deletions packages/theme-gungnir/components/ArticleHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<div class="icons">
<div
class="icon"
v-if="articleInfo.frontmatter.author || $themeConfig.author || $site.title"
v-if="articleInfo.frontmatter.author || $themeConfig.personalInfo.name || $site.title"
>
<v-icon name="fa-regular-user" />
<span>{{ articleInfo.frontmatter.author || $themeConfig.author || $site.title }}</span>
<span>{{ articleInfo.frontmatter.author || $themeConfig.personalInfo.name || $site.title }}</span>
</div>

<div
Expand Down
6 changes: 3 additions & 3 deletions packages/theme-gungnir/components/Common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<div class="personal-info-wrapper">
<div class="mobile-hero-avatar">
<img
:src="$withBase($themeConfig.authorAvatar)"
:src="$withBase($themeConfig.personalInfo.avatar)"
alt="hero"
/>
</div>
<p class="mobile-heading">{{ $themeConfig.author }}</p>
<p class="mobile-heading">{{ $themeConfig.personalInfo.name }}</p>
<SNS />
<hr>
</div>
Expand All @@ -39,7 +39,7 @@
<slot></slot>

<SearchPage
v-if="$themeConfig.search !== false && $frontmatter.search !== false"
v-if="$themeConfig.search && $frontmatter.search !== false"
@toggle-search="toggleSearch(false)"
/>
<Menu
Expand Down
18 changes: 9 additions & 9 deletions packages/theme-gungnir/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
>
<div
class="header-mask"
v-if="$themeConfig.bgImage[this.bgImageID].mask"
:style="{background: $themeConfig.bgImage[this.bgImageID].mask}"
v-if="$themeConfig.homeHeaderImages[this.bgImageID].mask"
:style="{background: $themeConfig.homeHeaderImages[this.bgImageID].mask}"
/>
<div
class="header-content"
:style="{'opacity': headerOpacity}"
>
<div class="hero-avatar hide-on-mobile">
<img
:src="$withBase($themeConfig.authorAvatar)"
:src="$withBase($themeConfig.personalInfo.avatar)"
alt="hero"
/>
</div>
Expand All @@ -32,8 +32,8 @@

<div class="hero-info">
<div class="hero-info__text">
<h1>{{ $themeConfig.author || $title }}</h1>
<p class="description">{{ $themeConfig.tagline || $description }}</p>
<h1>{{ $themeConfig.personalInfo.name || $title }}</h1>
<p class="description">{{ $themeConfig.personalInfo.description || $description }}</p>
</div>
</div>

Expand Down Expand Up @@ -91,8 +91,8 @@ export default {
},
computed: {
bgImagePath () {
if(this.$themeConfig.bgImage) {
var bgPath = `url(${this.$withBase(this.$themeConfig.bgImage[this.bgImageID].path)})`
if(this.$themeConfig.homeHeaderImages) {
var bgPath = `url(${this.$withBase(this.$themeConfig.homeHeaderImages[this.bgImageID].path)})`
return bgPath
}
else {
Expand All @@ -105,7 +105,7 @@ export default {
}
},
mounted() {
this.bgImageID = Math.floor(Math.random() * this.$themeConfig.bgImage.length)
this.bgImageID = Math.floor(Math.random() * this.$themeConfig.homeHeaderImages.length)
window.addEventListener('scroll', throttle(this.handleScroll, 50))
fetch('https://v1.hitokoto.cn')
Expand All @@ -124,7 +124,7 @@ export default {
methods: {
// switch to the next header image
switchImage(n) {
let len = this.$themeConfig.bgImage.length
let len = this.$themeConfig.homeHeaderImages.length
this.bgImageID = (this.bgImageID + n + len) % len
},
scrollToPost() {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/components/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- search button -->
<div
v-if="$themeConfig.search !== false && $frontmatter.search !== false"
v-if="$themeConfig.search && $frontmatter.search !== false"
class="nav-item"
>
<a
Expand Down
8 changes: 4 additions & 4 deletions packages/theme-gungnir/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export default {
|| (this.$page.id == 'posts' && this.$page.frontmatter.header_style == 'image')
// tags page with header image
|| (['Tags', 'Tag'].indexOf(this.$page.frontmatter.layout) != -1
&& this.$themeConfig.pageConfig.tags
&& this.$themeConfig.pageConfig.tags.bgImage)
&& this.$themeConfig.pages.tags
&& this.$themeConfig.pages.tags.bgImage)
// links page with header image
|| (this.$page.frontmatter.layout == 'Links'
&& this.$themeConfig.pageConfig.links
&& this.$themeConfig.pageConfig.links.bgImage)
&& this.$themeConfig.pages.links
&& this.$themeConfig.pages.links.bgImage)
) this.isInvert = false
else this.isInvert = true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/components/SNS.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="sns-wrapper">
<a
v-for="(user, platform) in $themeConfig.SNS"
v-for="(user, platform) in $themeConfig.personalInfo.sns"
:key="`${platform}-${user}`"
:href="snsLink(user, platform)"
target="_blank"
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/components/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default {
},
mounted () {
this.placeholder = this.$site.themeConfig.searchPlaceholder || '$ grep ...'
this.placeholder = this.$site.themeConfig.searchPlaceholder || ''
document.addEventListener('keydown', this.onHotkey)
},
Expand Down
42 changes: 41 additions & 1 deletion packages/theme-gungnir/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@ const path = require('path')
module.exports = (options, ctx) => {
const { themeConfig, siteConfig } = ctx

// default theme config
Object.assign(options, Object.assign({
search: true,
searchMaxSuggestions: 10,
searchPlaceholder: '$ grep ...',
smoothScroll: true,
sidebarDepth: 5,
codeTheme: 'gungnir-dark',
hitokoto: false,
comment: false,
analytics: false,
rss: false,
personalInfo: {},
homeHeaderImages: {},
pages: {},
footer: ''
}, options))

const { comment, analytics, rss } = options

return {
name: 'vuepress-theme-gungnir',
plugins: [
'@vuepress/search',
'@vuepress/plugin-nprogress',
Expand Down Expand Up @@ -80,11 +101,30 @@ module.exports = (options, ctx) => {
after: () => '</details>\n'
}
],
[
'@vssue/vuepress-plugin-vssue',
comment ? Object.assign({
platform: 'github',
}, comment) : false
],
[
'@renovamen/vuepress-plugin-reading-time', {
excludes: ['/about', '/tags/.*', '/links']
}
]
],
[
'@vuepress/google-analytics',
analytics && analytics.ga
? { 'ga': analytics.ga }
: false
],
[
'@renovamen/vuepress-plugin-baidu-tongji',
analytics && analytics.ba
? { 'ba': analytics.ba }
: false
],
['@renovamen/vuepress-plugin-rss', rss ? rss : false],
],

chainMarkdown(config) {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/layouts/Links.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<PageHeader :pageInfo="$themeConfig.pageConfig.links" />
<PageHeader :pageInfo="$themeConfig.pages.links" />
<Common class="links-wrapper">
<div class="links-group">
<div
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/layouts/Tag.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<PageHeader :pageInfo="$themeConfig.pageConfig.tags" />
<PageHeader :pageInfo="$themeConfig.pages.tags" />
<Common
class="tag-wrapper"
:sidebar="false"
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-gungnir/layouts/Tags.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<PageHeader :pageInfo="$themeConfig.pageConfig.tags" />
<PageHeader :pageInfo="$themeConfig.pages.tags" />
<Common
class="tags-wrapper"
:sidebar="false"
Expand Down

1 comment on commit 13e5b37

@vercel
Copy link

@vercel vercel bot commented on 13e5b37 Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.