-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
323 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const storagePrefix = function (base) { | ||
let p = base.replace(/^\//, "").replace(/\/$/, "").replace(/\//g, "."); | ||
return p ? p + "." : ""; | ||
}; | ||
|
||
const setStorage = function (name, value, base) { | ||
if (typeof localStorage === "undefined") { | ||
return; | ||
} | ||
localStorage[storagePrefix(base) + name] = value; | ||
}; | ||
|
||
const getStorage = function (name, base) { | ||
if (typeof localStorage === "undefined") { | ||
return; | ||
} | ||
name = storagePrefix(base) + name; | ||
if (typeof localStorage[name] === "undefined") { | ||
return; | ||
} | ||
return localStorage[name]; | ||
}; | ||
|
||
export { storagePrefix, getStorage, setStorage }; |
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,42 @@ | ||
<template> | ||
<ul class="code-language-switcher split"> | ||
<li v-for="(language, index) in $page.frontmatter.code" :key="index"> | ||
<a | ||
:class="{ active: $store.state.codeLanguage === language }" | ||
@click="$store.commit('changeCodeLanguage', language)" | ||
>{{ $site.themeConfig.codeLanguages[language] }}</a | ||
> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<style lang="stylus"> | ||
.code-language-switcher.split | ||
border-radius 0 | ||
</style> | ||
|
||
<script> | ||
import { getStorage } from "../Storage"; | ||
export default { | ||
mounted() { | ||
if ( | ||
this.$page.frontmatter.code.indexOf(this.$store.state.codeLanguage) === -1 | ||
) { | ||
let storageValue = getStorage("codeLanguage", this.$site.base); | ||
if ( | ||
typeof storageValue !== "undefined" && | ||
this.$page.frontmatter.code.indexOf(storageValue) !== -1 | ||
) { | ||
this.$store.commit("changeCodeLanguage", storageValue); | ||
} else { | ||
this.$store.commit( | ||
"changeCodeLanguage", | ||
this.$page.frontmatter.code[0] | ||
); | ||
} | ||
} | ||
}, | ||
}; | ||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<main class="page"> | ||
<!-- CodeLanguageSwitcher is the only addition to the default Page component --> | ||
<CodeLanguageSwitcher | ||
v-if="$page.frontmatter.split && $page.frontmatter.code" | ||
/> | ||
<slot name="top" /> | ||
|
||
<Content class="theme-default-content" /> | ||
<PageEdit /> | ||
|
||
<PageNav v-bind="{ sidebarItems }" /> | ||
|
||
<slot name="bottom" /> | ||
</main> | ||
</template> | ||
|
||
<script> | ||
import PageEdit from "@parent-theme/components/PageEdit.vue"; | ||
import PageNav from "@parent-theme/components/PageNav.vue"; | ||
import CodeLanguageSwitcher from "./CodeLanguageSwitcher.vue"; | ||
export default { | ||
components: { PageEdit, PageNav, CodeLanguageSwitcher }, | ||
props: ["sidebarItems"], | ||
}; | ||
</script> | ||
|
||
<style lang="stylus"> | ||
@require '~@parent-theme/styles/wrapper.styl' | ||
.page | ||
padding-bottom 2rem | ||
display block | ||
</style> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,4 +197,5 @@ div.table { | |
} | ||
|
||
@require '~@theme/styles/mobile.styl' | ||
@require '~@theme/styles/split.styl' | ||
|
Oops, something went wrong.