valaxy-theme-press 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/components/PressAlgoliaSearch.vue +208 -0
  2. package/components/PressArticle.vue +12 -6
  3. package/components/PressAside.vue +23 -11
  4. package/components/PressBackdrop.vue +1 -1
  5. package/components/PressCategories.vue +2 -2
  6. package/components/PressCategory.vue +13 -11
  7. package/components/PressFeatures.vue +1 -1
  8. package/components/PressFooter.vue +1 -1
  9. package/components/PressHome.vue +1 -1
  10. package/components/PressHomeFeatures.vue +1 -0
  11. package/components/PressHomeHero.vue +7 -8
  12. package/components/PressLocalNav.vue +9 -9
  13. package/components/PressNav.vue +30 -5
  14. package/components/PressNavBar.vue +94 -0
  15. package/components/PressNavBarAppearance.vue +5 -0
  16. package/components/PressNavBarHamburger.vue +79 -0
  17. package/components/PressNavBarMenu.vue +14 -0
  18. package/components/PressNavBarSearch.vue +40 -0
  19. package/components/PressNavBarSocialLinks.vue +26 -0
  20. package/components/PressNavBarTranslations.vue +5 -0
  21. package/components/{nav/PressNavItemGroup.vue → PressNavItemGroup.vue} +2 -2
  22. package/components/{nav/PressNavItemLink.vue → PressNavItemLink.vue} +2 -1
  23. package/components/PressNavScreen.vue +95 -0
  24. package/components/PressNavScreenAppearance.vue +32 -0
  25. package/components/PressNavScreenMenu.vue +22 -0
  26. package/components/PressNavScreenMenuGroup.vue +115 -0
  27. package/components/PressNavScreenMenuGroupLink.vue +32 -0
  28. package/components/PressNavScreenMenuGroupSection.vue +37 -0
  29. package/components/PressNavScreenMenuLink.vue +33 -0
  30. package/components/PressNavScreenSocialLinks.vue +13 -0
  31. package/components/PressNavScreenTranslations.vue +7 -0
  32. package/components/PressOutline.vue +1 -0
  33. package/components/PressPostList.vue +3 -3
  34. package/components/PressSidebar.vue +10 -9
  35. package/components/PressSocialLink.vue +40 -0
  36. package/components/PressSocialLinks.vue +26 -0
  37. package/components/ValaxyMain.vue +46 -33
  38. package/composables/nav.ts +37 -0
  39. package/config/index.ts +5 -0
  40. package/layouts/layout.vue +0 -1
  41. package/package.json +3 -3
  42. package/pages/[..all].vue +1 -0
  43. package/setup/main.ts +5 -3
  44. package/styles/css-vars.scss +11 -6
  45. package/styles/markdown.scss +10 -9
  46. package/types/index.d.ts +17 -1
  47. package/utils/index.ts +9 -0
  48. package/valaxy.config.ts +5 -0
  49. package/components/DocsBoard.vue +0 -24
  50. package/components/nav/PressNavBar.vue +0 -111
  51. /package/components/{nav/PressSwitchAppearance.vue → PressSwitchAppearance.vue} +0 -0
@@ -0,0 +1,40 @@
1
+ <script lang="ts" setup>
2
+ defineProps<{
3
+ icon: string
4
+ link: string
5
+ }>()
6
+ </script>
7
+
8
+ <template>
9
+ <a
10
+ class="pr-social-link"
11
+ :href="link"
12
+ target="_blank"
13
+ rel="noopener"
14
+ >
15
+ <div :class="icon" />
16
+ </a>
17
+ </template>
18
+
19
+ <style scoped>
20
+ .pr-social-link {
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ width: 36px;
25
+ height: 36px;
26
+ color: var(--pr-c-text-2);
27
+ transition: color 0.5s;
28
+ }
29
+
30
+ .pr-social-link:hover {
31
+ color: var(--pr-c-text-1);
32
+ transition: color 0.25s;
33
+ }
34
+
35
+ .pr-social-link > :deep(svg) {
36
+ width: 20px;
37
+ height: 20px;
38
+ fill: currentColor;
39
+ }
40
+ </style>
@@ -0,0 +1,26 @@
1
+ <script lang="ts" setup>
2
+ import type { PressTheme } from '../types'
3
+
4
+ defineProps<{
5
+ links: PressTheme.SocialLink[]
6
+ }>()
7
+ </script>
8
+
9
+ <template>
10
+ <div class="pr-social-links">
11
+ <PressSocialLink
12
+ v-for="{ link, icon } in links"
13
+ :key="link"
14
+ :icon="icon"
15
+ :link="link"
16
+ />
17
+ </div>
18
+ </template>
19
+
20
+ <style scoped>
21
+ .pr-social-links {
22
+ display: flex;
23
+ flex-wrap: wrap;
24
+ justify-content: center;
25
+ }
26
+ </style>
@@ -1,73 +1,86 @@
1
1
  <script lang="ts" setup>
2
2
  import type { PageData, Post } from 'valaxy'
3
- import { useConfig, useFrontmatter, useLayout, useSidebar } from 'valaxy'
3
+ import { useFrontmatter, useLayout, useSidebar, useSiteConfig } from 'valaxy'
4
+ import { computed } from 'vue'
5
+ import { useI18n } from 'vue-i18n'
6
+ import { getLocaleTitle } from '../utils'
4
7
 
5
8
  defineProps<{
6
9
  frontmatter: Post
7
10
  data?: PageData
8
11
  }>()
9
12
 
10
- const config = useConfig()
13
+ const siteConfig = useSiteConfig()
11
14
  const frontmatter = useFrontmatter()
12
15
 
13
16
  const { hasSidebar } = useSidebar()
14
17
  const isHome = useLayout('home')
18
+ const layout = useLayout()
19
+
20
+ const { locale } = useI18n()
21
+ const localeTitle = computed(() => getLocaleTitle(locale.value, frontmatter.value))
15
22
  </script>
16
23
 
17
24
  <template>
18
25
  <main
19
26
  class="press-main flex" :class="{
20
- 'has-sidebar': hasSidebar,
27
+ 'has-sidebar': hasSidebar && layout !== 'post',
21
28
  }"
22
29
  >
23
30
  <div
24
31
  w="full" flex="~" :class="{
25
32
  'px-6 md:pl-12': hasSidebar,
33
+ 'has-aside': !isHome,
26
34
  }" p="t-4"
35
+ class="relative"
27
36
  >
28
- <slot name="main">
29
- <div class="content" w="full" :class="{ 'm-auto': !hasSidebar }" flex="~ col grow" p="lt-md:0">
30
- <slot name="main-header" />
31
- <slot name="main-header-after" />
37
+ <div class="container" flex="~ grow" justify="between">
38
+ <slot name="main">
39
+ <div class="content" w="full" :class="{ 'm-auto': !hasSidebar }" flex="~ col grow" p="lt-md:0">
40
+ <slot name="main-header" />
41
+ <slot name="main-header-after" />
32
42
 
33
- <slot name="main-content">
34
- <ValaxyMd class="prose mx-auto w-full max-w-4xl" :frontmatter="frontmatter">
35
- <h1 v-if="hasSidebar && !isHome && frontmatter.title" :id="frontmatter.title" tabindex="-1">
36
- {{ frontmatter.title }}
37
- <a class="header-anchor" :href="`#${frontmatter.title}`" aria-hidden="true">#</a>
38
- </h1>
39
- <slot name="main-content-md" />
40
- <slot />
41
- </ValaxyMd>
43
+ <slot name="main-content">
44
+ <Transition appear>
45
+ <ValaxyMd class="prose mx-auto w-full max-w-4xl" :frontmatter="frontmatter">
46
+ <h1 v-if="hasSidebar && !isHome && frontmatter.title" :id="frontmatter.title" tabindex="-1">
47
+ {{ localeTitle }}
48
+ <a class="header-anchor" :href="`#${frontmatter.title}`" aria-hidden="true">#</a>
49
+ </h1>
50
+ <slot name="main-content-md" />
51
+ <slot />
52
+ </ValaxyMd>
53
+ </Transition>
42
54
 
43
- <PressDocFooter v-if="!isHome" class="pb-8 max-w-4xl" w="full" m="auto" />
55
+ <PressDocFooter v-if="!isHome" class="pb-8 max-w-4xl" w="full" m="auto" />
44
56
 
45
- <slot name="main-content-after" />
46
- </slot>
47
- </div>
57
+ <slot name="main-content-after" />
58
+ </slot>
59
+ </div>
48
60
 
49
- <slot name="main-nav-before" />
61
+ <slot name="main-nav-before" />
50
62
 
51
- <slot name="main-nav" />
63
+ <slot name="main-nav" />
52
64
 
53
- <slot name="main-nav-after" />
65
+ <slot name="main-nav-after" />
54
66
 
55
- <slot v-if="config.comment.enable && frontmatter.comment !== false" name="comment" />
67
+ <slot v-if="siteConfig.comment.enable && frontmatter.comment !== false" name="comment" />
56
68
 
57
- <slot name="footer" />
58
- </slot>
69
+ <slot name="footer" />
70
+ </slot>
59
71
 
60
- <slot name="aside">
61
- <PressAside v-if="!isHome" />
62
- </slot>
72
+ <slot name="aside">
73
+ <PressAside v-if="!isHome" />
74
+ </slot>
75
+ </div>
63
76
  </div>
64
77
  </main>
65
78
  </template>
66
79
 
67
- <style lang="scss">
68
- @use 'valaxy/client/styles/mixins' as *;
80
+ <style lang="scss" scoped>
81
+ @use 'valaxy/client/styles/mixins/index.scss' as *;
69
82
 
70
- @include media('md') {
83
+ @include screen('md') {
71
84
  .press-main {
72
85
  &.has-sidebar {
73
86
  padding-top: var(--pr-nav-height);
@@ -76,7 +89,7 @@ const isHome = useLayout('home')
76
89
  }
77
90
  }
78
91
 
79
- @include media('xl') {
92
+ @include screen('xl') {
80
93
  .content{
81
94
  // 8px scrollbar width
82
95
  max-width: calc(100vw - 2 * var(--va-sidebar-width) - 2.5rem);
@@ -0,0 +1,37 @@
1
+ import { ref, watch } from 'vue'
2
+ import { useRoute } from 'vue-router'
3
+
4
+ export function useNav() {
5
+ const isScreenOpen = ref(false)
6
+
7
+ function openScreen() {
8
+ isScreenOpen.value = true
9
+ window.addEventListener('resize', closeScreenOnTabletWindow)
10
+ }
11
+
12
+ function closeScreen() {
13
+ isScreenOpen.value = false
14
+ window.removeEventListener('resize', closeScreenOnTabletWindow)
15
+ }
16
+
17
+ function toggleScreen() {
18
+ isScreenOpen.value ? closeScreen() : openScreen()
19
+ }
20
+
21
+ /**
22
+ * Close screen when the user resizes the window wider than tablet size.
23
+ */
24
+ function closeScreenOnTabletWindow() {
25
+ window.outerWidth >= 768 && closeScreen()
26
+ }
27
+
28
+ const route = useRoute()
29
+ watch(() => route.path, closeScreen)
30
+
31
+ return {
32
+ isScreenOpen,
33
+ openScreen,
34
+ closeScreen,
35
+ toggleScreen,
36
+ }
37
+ }
package/config/index.ts CHANGED
@@ -6,6 +6,7 @@ export const anonymousImage = 'https://cdn.yunyoujun.cn/img/avatar/none.jpg'
6
6
  * Default Config
7
7
  */
8
8
  export const defaultThemeConfig: ThemeConfig = {
9
+ logo: '',
9
10
  outlineTitle: 'On this page',
10
11
 
11
12
  colors: {
@@ -20,5 +21,9 @@ export const defaultThemeConfig: ThemeConfig = {
20
21
  text: 'Edit this page on GitHub',
21
22
  },
22
23
 
24
+ socialLinks: [
25
+
26
+ ],
27
+
23
28
  footer: {},
24
29
  }
@@ -55,4 +55,3 @@ const layout = useLayout()
55
55
  <PressFooter />
56
56
  </div>
57
57
  </template>
58
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valaxy-theme-press",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Docs Theme for Valaxy",
5
5
  "author": {
6
6
  "email": "me@yunyoujun.cn",
@@ -19,8 +19,8 @@
19
19
  "main": "node/index.ts",
20
20
  "types": "types/index.d.ts",
21
21
  "dependencies": {
22
- "@docsearch/css": "^3.3.0",
23
- "@docsearch/js": "^3.3.0"
22
+ "@docsearch/css": "^3.3.3",
23
+ "@docsearch/js": "^3.3.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "valaxy": "workspace:*"
package/pages/[..all].vue CHANGED
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { useI18n } from 'vue-i18n'
3
+
3
4
  const { t } = useI18n()
4
5
  </script>
5
6
 
package/setup/main.ts CHANGED
@@ -8,7 +8,7 @@ export default defineAppSetup((ctx) => {
8
8
 
9
9
  window.addEventListener(
10
10
  'click',
11
- (e) => {
11
+ async (e) => {
12
12
  const link = (e.target as Element).closest('a')
13
13
  if (link) {
14
14
  const { protocol, hostname, pathname, hash, target } = link
@@ -29,7 +29,9 @@ export default defineAppSetup((ctx) => {
29
29
  e.preventDefault()
30
30
  // scroll between hash anchors in the same page
31
31
  if (hash && hash !== currentUrl.hash) {
32
- history.pushState(null, '', hash)
32
+ await router.push({ hash })
33
+ history.replaceState({ ...history.state }, '')
34
+
33
35
  // still emit the event so we can listen to it in themes
34
36
  window.dispatchEvent(new Event('hashchange'))
35
37
  // use smooth scroll when clicking on header anchor links
@@ -61,7 +63,7 @@ function scrollTo(el: HTMLElement, hash: string, smooth = false) {
61
63
  try {
62
64
  target = el.classList.contains('header-anchor')
63
65
  ? el
64
- : (decodeURIComponent(hash) && document.querySelector(decodeURIComponent(hash))) || null
66
+ : ((decodeURIComponent(hash) && document.querySelector(decodeURIComponent(hash))) || null)
65
67
  }
66
68
  catch (e) {
67
69
  console.warn(e)
@@ -3,8 +3,11 @@
3
3
  }
4
4
 
5
5
  :root {
6
+ --pr-c-bg: var(--va-c-bg);
7
+
6
8
  --pr-c-text-code: #374562;
7
9
  --pr-c-text-1: #213547;
10
+ --pr-c-text-2: rgba(60, 60, 60, .7);
8
11
 
9
12
  // aside
10
13
  --pr-aside-text-1: var(--pr-c-text-1);
@@ -18,14 +21,15 @@
18
21
  --pr-nav-height: var(--pr-nav-height-mobile);
19
22
  --pr-nav-height-mobile: 60px;
20
23
  --pr-nav-text: var(--pr-c-text-1);
24
+ --pr-nav-screen-bg-color: var(--pr-c-bg);
21
25
 
22
26
  // z-index
23
- --va-z-overlay: var(--pr-z-index-backdrop);
24
- --pr-z-index-local-nav: 8;
25
- --pr-z-index-nav: 9;
26
- --pr-z-index-backdrop: 10;
27
- --pr-z-index-aside: 11;
28
- --pr-z-index-sidebar: 12;
27
+ --va-z-overlay: var(--pr-z-backdrop);
28
+ --pr-z-local-nav: 8;
29
+ --pr-z-nav: 9;
30
+ --pr-z-backdrop: 10;
31
+ --pr-z-aside: 11;
32
+ --pr-z-sidebar: 12;
29
33
 
30
34
  // switch
31
35
  --pr-switch-divider: rgba(60, 60, 60, 0.29);
@@ -35,6 +39,7 @@
35
39
  .dark {
36
40
  --pr-c-text-code: var(--pr-c-indigo-lighter);
37
41
  --pr-c-text-1: #ffffffde;
42
+ --pr-c-text-2: rgba(235, 235, 235, .6);
38
43
 
39
44
  // aside
40
45
  --pr-aside-text-2: #ebebeb99;
@@ -1,4 +1,8 @@
1
- @use "valaxy/client/styles/mixins" as *;
1
+ @use "valaxy/client/styles/mixins/index.scss" as *;
2
+
3
+ :root {
4
+ --va-code-mobile-margin-x: -1.5rem;
5
+ }
2
6
 
3
7
  .prose {
4
8
  --un-prose-body: var(--va-c-text);
@@ -19,7 +23,7 @@
19
23
  transition: all 0.4s;
20
24
 
21
25
  &:hover {
22
- border-bottom-color: var(--va-c-brand);
26
+ // border-bottom-color: var(--va-c-brand);
23
27
  }
24
28
  }
25
29
 
@@ -38,12 +42,9 @@
38
42
  content: none;
39
43
  }
40
44
  }
41
- }
42
45
 
43
- @include mobile {
44
- .markdown-body {
45
- div[class*="language-"] {
46
- margin: 0 -1.5rem;
47
- }
46
+ ul {
47
+ margin-top: 0em;
48
+ margin-bottom: 0.25em;
48
49
  }
49
- }
50
+ }
package/types/index.d.ts CHANGED
@@ -9,6 +9,11 @@ export namespace PressTheme {
9
9
  copyright?: string;
10
10
  }
11
11
 
12
+ export interface SocialLink {
13
+ icon: string
14
+ link: string
15
+ }
16
+
12
17
  export interface EditLink {
13
18
  /**
14
19
  * Pattern for edit link.
@@ -26,6 +31,8 @@ export namespace PressTheme {
26
31
  }
27
32
 
28
33
  export interface Config {
34
+ logo: string
35
+
29
36
  /**
30
37
  * toc title
31
38
  * @default 'On this page'
@@ -39,6 +46,7 @@ export namespace PressTheme {
39
46
  */
40
47
  primary: string
41
48
  }
49
+
42
50
 
43
51
  nav: Array<NavItem>
44
52
  sidebar: string[]
@@ -46,6 +54,14 @@ export namespace PressTheme {
46
54
  editLink: EditLink
47
55
 
48
56
  footer: Footer
57
+
58
+ socialLinks: SocialLink[]
59
+
60
+ // label
61
+ /**
62
+ * Toggle dark label
63
+ */
64
+ darkModeSwitchLabel?: string
49
65
  }
50
66
  }
51
67
 
@@ -68,4 +84,4 @@ export type NavItem = NavItemLink | NavItemGroup
68
84
  * Theme Config
69
85
  */
70
86
  export type ThemeConfig = PressTheme.Config
71
- export type ThemeUserConfig = Partial<ThemeConfig>
87
+ export type UserThemeConfig = Partial<ThemeConfig>
package/utils/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * get locale title
3
+ * @param locale
4
+ * @param frontmatter
5
+ * @returns
6
+ */
7
+ export function getLocaleTitle(locale: string, frontmatter: any) {
8
+ return frontmatter[`title${locale === 'en' ? '' : `_${locale}`}`]
9
+ }
package/valaxy.config.ts CHANGED
@@ -32,6 +32,11 @@ export default defineTheme<ThemeConfig>((options) => {
32
32
  return {
33
33
  themeConfig: defaultThemeConfig,
34
34
  vite: {
35
+ build: {
36
+ rollupOptions: {
37
+ external: ['valaxy-addon-algolia'],
38
+ },
39
+ },
35
40
  plugins: [ThemeVitePlugin(options)],
36
41
  },
37
42
  }
@@ -1,24 +0,0 @@
1
- <script lang="ts" setup>
2
- import { useI18n } from 'vue-i18n'
3
-
4
- const { t } = useI18n()
5
- </script>
6
-
7
- <template>
8
- <YunBoard m="t-4">
9
- 这里是 Valaxy 的文档兼测试站点
10
-
11
- <ul>
12
- <li>
13
- <router-link to="/docs" :title="t('docs.view_docs')">
14
- {{ t('docs.view_docs') }}
15
- </router-link>
16
- </li>
17
- <li>
18
- <router-link class="flex justify-center" to="/examples">
19
- Examples
20
- </router-link>
21
- </li>
22
- </ul>
23
- </YunBoard>
24
- </template>
@@ -1,111 +0,0 @@
1
- <script lang="ts" setup>
2
- import { useConfig, useSidebar } from 'valaxy'
3
- import { useThemeConfig } from '../../composables'
4
- import PressSwitchAppearance from './PressSwitchAppearance.vue'
5
- import PressNavItemLink from './PressNavItemLink.vue'
6
- import PressNavItemGroup from './PressNavItemGroup.vue'
7
-
8
- defineProps<{
9
- isScreenOpen?: boolean
10
- }>()
11
-
12
- defineEmits<{
13
- (e: 'toggle-screen'): void
14
- }>()
15
-
16
- const { hasSidebar } = useSidebar()
17
-
18
- const config = useConfig()
19
- const themeConfig = useThemeConfig()
20
- </script>
21
-
22
- <template>
23
- <div class="press-navbar flex justify-between items-center px-6 py-4" :class="{ 'has-sidebar': hasSidebar }">
24
- <router-link class="text-xl" to="/" :aria-label="config.title">
25
- <span class="md:inline">{{ config.title }}</span>
26
- </router-link>
27
- <div class="self-stretch flex justify-center items-center text-sm leading-5">
28
- <template v-for="item in themeConfig.nav" :key="item.text">
29
- <PressNavItemLink v-if="'link' in item" class="px-2" :item="item" />
30
- <PressNavItemGroup v-else class="px-2" :item="item" />
31
- </template>
32
- <PressToggleLocale p="x-2" />
33
- <PressSwitchAppearance m="l-2" />
34
- </div>
35
- </div>
36
- </template>
37
-
38
- <style lang="scss">
39
- @use 'valaxy/client/styles/mixins' as *;
40
-
41
- :root {
42
- --pr-navbar-c-bg: rgba(255, 255, 255, 0.8);
43
- }
44
-
45
- .dark {
46
- --pr-navbar-c-bg: rgba(24, 24, 24, 0.8);
47
- }
48
-
49
- .press-navbar {
50
- position: relative;
51
- border-bottom: 1px solid var(--pr-c-divider-light);
52
- padding: 0 8px 0 24px;
53
- height: var(--pr-nav-height);
54
- transition: border-color 0.5s;
55
- background-color: var(--pr-navbar-c-bg);
56
- }
57
-
58
- @include media('md') {
59
- .press-navbar {
60
- padding: 0 32px;
61
- }
62
- }
63
-
64
- @include media('md') {
65
- .press-navbar.has-sidebar .content {
66
- margin-right: -32px;
67
- padding-right: 32px;
68
- -webkit-backdrop-filter: saturate(50%) blur(8px);
69
- backdrop-filter: saturate(50%) blur(8px);
70
- }
71
-
72
- @supports not (backdrop-filter: saturate(50%) blur(8px)) {
73
- .press-navbar.has-sidebar .content {
74
- background: rgba(255, 255, 255, 0.95);
75
- }
76
-
77
- .dark .press-navbar.has-sidebar .content {
78
- background: rgba(36, 36, 36, 0.95);
79
- }
80
- }
81
- }
82
-
83
- .container {
84
- display: flex;
85
- justify-content: space-between;
86
- margin: 0 auto;
87
- max-width: calc(var(--pr-layout-max-width) - 64px);
88
- }
89
-
90
- .menu + .translations::before,
91
- .menu + .appearance::before,
92
- .menu + .social-links::before,
93
- .translations + .appearance::before,
94
- .appearance + .social-links::before {
95
- margin-right: 8px;
96
- margin-left: 8px;
97
- width: 1px;
98
- height: 24px;
99
- background-color: var(--pr-c-divider-light);
100
- content: "";
101
- }
102
-
103
- .menu + .appearance::before,
104
- .translations + .appearance::before {
105
- margin-right: 16px;
106
- }
107
-
108
- .appearance + .social-links::before {
109
- margin-left: 16px;
110
- }
111
- </style>