valaxy-theme-hairy 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import { capitalize, computed } from 'vue'
3
- import { useConfig, useSiteConfig, useThemeConfig } from 'valaxy'
3
+ import { useConfig, useSiteConfig, useThemeConfig, useRuntimeConfig } from 'valaxy'
4
4
  import { useI18n } from 'vue-i18n'
5
5
  import pkg from 'valaxy/package.json'
6
6
  import type { HairyTheme } from 'valaxy-theme-hairy'
@@ -19,8 +19,8 @@ const isThisYear = computed(() => {
19
19
 
20
20
  const poweredHtml = computed(() => t('footer.powered', [`<a href="${pkg.repository}" target="_blank" rel="noopener">Valaxy</a> v${pkg.version}`]))
21
21
  const footerIcon = computed(() => themeConfig.value.footer?.icon)
22
-
23
- // const frontmatter = useFrontmatter()
22
+ const runtimeConfig = useRuntimeConfig()
23
+ const addonWaline = computed(() => runtimeConfig.value.addons['valaxy-addon-waline'])
24
24
  </script>
25
25
 
26
26
  <template>
@@ -45,11 +45,14 @@ const footerIcon = computed(() => themeConfig.value.footer?.icon)
45
45
  </a>
46
46
 
47
47
  <span>{{ sideConfig.author.name }}</span>
48
- <span class="mx-2">|</span>
49
- <span class="flex items-center">
50
- <div class="i-ri-eye-fill mr-1" />
51
- <span class="waline-pageview-count" data-path="/">-</span>
52
- </span>
48
+ <template v-if="addonWaline.options?.pageview">
49
+ <span class="mx-2">|</span>
50
+ <span class="flex items-center">
51
+ <div class="i-ri-eye-fill mr-1" />
52
+ <span class="waline-pageview-count" data-path="/" />
53
+ </span>
54
+ </template>
55
+
53
56
  </div>
54
57
  <div v-if="themeConfig.footer.powered" class="powered" m="2">
55
58
  <span v-html="poweredHtml" /> | <span>{{ t('footer.theme') }} - <a :href="themeConfig.pkg.homepage" :title="`valaxy-theme-${config.theme}`" target="_blank">{{ capitalize(config.theme) }}</a> v{{ themeConfig.pkg.version }}</span>
@@ -2,8 +2,8 @@
2
2
  import { computed, provide, useCssVars, useSlots } from 'vue'
3
3
  import { renderOverlay } from '@overlastic/vue'
4
4
  import type { ImageViewerProps } from 'element-plus'
5
- import { atWillToUnit } from '@hairy/utils'
6
5
  import HairyImageViewer from './parts/HairyImageViewer.vue'
6
+ import { atWillToUnit } from '../utils';
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  row?: string | number
@@ -2,8 +2,8 @@
2
2
  import { provide, useCssVars } from 'vue'
3
3
  import { renderOverlay } from '@overlastic/vue'
4
4
  import type { ImageViewerProps } from 'element-plus'
5
- import { atWillToUnit } from '@hairy/utils'
6
5
  import HairyImageViewer from './HairyImageViewer.vue'
6
+ import { atWillToUnit } from '../../utils';
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  row?: string | number
@@ -59,7 +59,7 @@ function displayCategory(keys: string | string[] = []) {
59
59
  </span>
60
60
  </a>
61
61
  <div class="text-base leading-6 font-medium">
62
- <a class="link cursor-pointer" aria-label="read more" @click="onReadMore">
62
+ <a class="link flex gap-2 cursor-pointer" aria-label="read more" @click="onReadMore">
63
63
  <span v-if="reverse">←</span>
64
64
  <span class="hidden md:block">Read more</span>
65
65
  <span v-if="!reverse">→</span>
@@ -9,7 +9,7 @@ const route = useRoute()
9
9
  <div class="border-t border-gray-200 dark:border-gray-600" />
10
10
  <div class="flex items-center justify-end mt-2">
11
11
  <div class="i-ri-eye-fill mr-2" />
12
- 阅读次数 <span class="waline-pageview-count mx-2" :data-path="route.path"> - </span>
12
+ 阅读次数 <span class="waline-pageview-count mx-2" :data-path="route.path" />
13
13
  </div>
14
14
  </div>
15
15
  </template>
package/layouts/post.vue CHANGED
@@ -1,7 +1,8 @@
1
1
  <script lang="ts" setup>
2
2
  import { ElTag, dayjs } from 'element-plus'
3
- import { useFrontmatter } from 'valaxy'
3
+ import { useFrontmatter, useRuntimeConfig } from 'valaxy'
4
4
  import { useRouter } from 'vue-router'
5
+ import { computed } from 'vue'
5
6
 
6
7
  import 'element-plus/theme-chalk/el-tag.css'
7
8
 
@@ -13,6 +14,8 @@ defineProps<{
13
14
  }
14
15
  }>()
15
16
 
17
+ const runtimeConfig = useRuntimeConfig()
18
+ const addonWaline = computed(() => runtimeConfig.value.addons['valaxy-addon-waline'])
16
19
  const router = useRouter()
17
20
  const post = useFrontmatter()
18
21
 
@@ -43,7 +46,7 @@ function displayTag(tag: string) {
43
46
  <HairyImageGlobal>
44
47
  <router-view />
45
48
  </HairyImageGlobal>
46
- <HairyPostFooter />
49
+ <HairyPostFooter v-if="addonWaline.options?.pageview" />
47
50
  </template>
48
51
  <template #slide>
49
52
  <HairyTabbar />
@@ -1,8 +1,8 @@
1
1
  import './loading.scss'
2
2
  import { ref } from 'vue'
3
3
  import type { ViteSSGContext } from 'vite-ssg'
4
- import { createDeferred } from '@hairy/utils'
5
4
  import Seto from '../styles/fonts/Seto.ttf?url'
5
+ import { createDeferred } from '../utils'
6
6
 
7
7
  export const fontFaceDeferred = createDeferred<void>()
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valaxy-theme-hairy",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "packageManager": "pnpm@8.10.5",
5
5
  "author": {
6
6
  "email": "wwu710632@gmail.com",
@@ -21,7 +21,6 @@
21
21
  "main": "client/index.ts",
22
22
  "types": "types/index.d.ts",
23
23
  "dependencies": {
24
- "@hairy/utils": "^0.6.8",
25
24
  "@overlastic/vue": "^0.4.7",
26
25
  "element-plus": "^2.7.6",
27
26
  "pinia": "^2.1.7",
package/utils/index.ts CHANGED
@@ -1,37 +1,2 @@
1
- export function ejectWindow(url: string) {
2
- const link = document.createElement('a')
3
- link.href = url
4
- link.target = '_blank'
5
- link.click()
6
- link.remove()
7
- }
8
-
9
- export function riposte<T>(...args: [cond: boolean, value: T][]) {
10
- for (const [cond, value] of args) {
11
- if (cond)
12
- return value
13
- }
14
- }
15
-
16
- export function toArray<T>(value: T | T[]): T[] {
17
- if (Array.isArray(value))
18
- return value as any
19
- else return [value].filter(Boolean) as any
20
- }
21
-
22
- export function removeTags(content = '') {
23
- return content
24
- .replace(/<\/?[^>]*>/g, '')
25
- .replace(/[|]*\n/, '')
26
- }
27
-
28
- export function getArchiveLink(year?: string, month?: string) {
29
- if (!year)
30
- return '/archives/'
31
- if (!month)
32
- return `/archives/${year}`
33
- if (month)
34
- return `/archives/${year}/${month}`
35
-
36
- return ''
37
- }
1
+ export * from './size'
2
+ export * from './util'
package/utils/size.ts ADDED
@@ -0,0 +1,40 @@
1
+
2
+ function isString(val: any) {
3
+ return typeof val === 'string'
4
+ }
5
+
6
+ function isNumber(val: any) {
7
+ return typeof val === 'number'
8
+ }
9
+
10
+ export function atWillToUnit(value: any, unit = 'px') {
11
+ if (!(isString(value) || isNumber(value)))
12
+ return ''
13
+ return (isString(value) && /\D/g.test(value)) ? value : value + unit
14
+ }
15
+
16
+ /** size 转换配置 */
17
+ export type AtWillSize = any | [any, any] | { width: any; height: any }
18
+ export interface Size { width: string; height: string }
19
+
20
+ /**
21
+ * 将 size 转换为宽高,用于元素宽高
22
+ * @param size AtWillSize
23
+ * @returns
24
+ */
25
+ export function atWillToSize(size: AtWillSize, unit?: string): Size {
26
+ const _atWillToUnit = (value: any) => atWillToUnit(value, unit)
27
+ // 单数值正方形
28
+ if (typeof size === 'string' || typeof size === 'number')
29
+ return { width: _atWillToUnit(size), height: _atWillToUnit(size) }
30
+
31
+ // 数组形式尺寸
32
+ if (Array.isArray(size))
33
+ return { width: _atWillToUnit(size[0]), height: _atWillToUnit(size[1]) }
34
+
35
+ // 对象形式尺寸
36
+ if (typeof size === 'object')
37
+ return { width: _atWillToUnit(size.width), height: _atWillToUnit(size.height) }
38
+
39
+ return { width: '', height: '' }
40
+ }
package/utils/util.ts ADDED
@@ -0,0 +1,59 @@
1
+ export function ejectWindow(url: string) {
2
+ const link = document.createElement('a')
3
+ link.href = url
4
+ link.target = '_blank'
5
+ link.click()
6
+ link.remove()
7
+ }
8
+
9
+ export function riposte<T>(...args: [cond: boolean, value: T][]) {
10
+ for (const [cond, value] of args) {
11
+ if (cond)
12
+ return value
13
+ }
14
+ }
15
+
16
+ export function toArray<T>(value: T | T[]): T[] {
17
+ if (Array.isArray(value))
18
+ return value as any
19
+ else return [value].filter(Boolean) as any
20
+ }
21
+
22
+ export function removeTags(content = '') {
23
+ return content
24
+ .replace(/<\/?[^>]*>/g, '')
25
+ .replace(/[|]*\n/, '')
26
+ }
27
+
28
+ export function getArchiveLink(year?: string, month?: string) {
29
+ if (!year)
30
+ return '/archives/'
31
+ if (!month)
32
+ return `/archives/${year}`
33
+ if (month)
34
+ return `/archives/${year}/${month}`
35
+
36
+ return ''
37
+ }
38
+
39
+ export type Deferred<T = void> = Promise<T> & {
40
+ resolve: (value: T) => void
41
+ reject: (value?: any) => void
42
+ }
43
+
44
+ export function createDeferred<T = void>(): Deferred<T> {
45
+ let resolve: any, reject: any
46
+
47
+ const promise = new Promise<any>((_resolve, _reject) => {
48
+ resolve = _resolve
49
+ reject = _reject
50
+ }) as unknown as any
51
+
52
+ promise.resolve = (v: any) => {
53
+ resolve(v)
54
+ return promise
55
+ }
56
+ promise.reject = reject
57
+
58
+ return promise
59
+ }