-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing title and desc in 404 and custom theme.
- Loading branch information
Showing
5 changed files
with
64 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import updateMeta from './updateMeta' | ||
export default [updateMeta] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export default { | ||
created () { | ||
if (this.$ssrContext) { | ||
this.$ssrContext.title = this.$title | ||
this.$ssrContext.lang = this.$lang | ||
this.$ssrContext.description = this.$page.description || this.$description | ||
} | ||
}, | ||
mounted () { | ||
// update title / meta tags | ||
this.currentMetaTags = [] | ||
const updateMeta = () => { | ||
document.title = this.$title | ||
document.documentElement.lang = this.$lang | ||
const meta = [ | ||
{ | ||
name: 'description', | ||
content: this.$description | ||
}, | ||
...(this.$page.frontmatter.meta || []) | ||
] | ||
this.currentMetaTags = updateMetaTags(meta, this.currentMetaTags) | ||
} | ||
this.$watch('$page', updateMeta) | ||
updateMeta() | ||
}, | ||
beforeDestroy () { | ||
updateMetaTags(null, this.currentMetaTags) | ||
} | ||
} | ||
|
||
function updateMetaTags (meta, current) { | ||
if (current) { | ||
current.forEach(c => { | ||
document.head.removeChild(c) | ||
}) | ||
} | ||
if (meta) { | ||
return meta.map(m => { | ||
const tag = document.createElement('meta') | ||
Object.keys(m).forEach(key => { | ||
tag.setAttribute(key, m[key]) | ||
}) | ||
document.head.appendChild(tag) | ||
return tag | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable */ | ||
import rootMixins from '@app/root-mixins' | ||
function injectRootMixins (options) { | ||
if (!options.mixins) { | ||
options.mixins = [] | ||
} | ||
options.mixins.push(...rootMixins) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters