@frontfactory/vitepress-theme 1.5.0 → 1.5.2

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.
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@frontfactory/vitepress-theme",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Editorial VitePress theme — hairline rules, numbered sections and monospaced metadata.",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "build": "sass --no-source-map --pkg-importer=node --load-path=node_modules src/styles/index.scss dist/style.css",
7
+ "build": "sass --style=compressed --no-source-map --pkg-importer=node --load-path=node_modules src/styles/index.scss dist/style.css",
8
8
  "dev": "npm run build -- --watch",
9
9
  "dev:playground": "npm run build && vitepress dev playground",
10
10
  "build:playground": "npm run build && vitepress build playground",
11
11
  "typecheck": "vue-tsc --noEmit",
12
+ "lint:js": "eslint .",
13
+ "lint:css": "stylelint \"src/**/*.scss\"",
14
+ "lint": "npm run lint:js && npm run lint:css",
12
15
  "prepare": "husky",
13
16
  "prepack": "npm run build",
14
17
  "release": "semantic-release"
@@ -32,17 +35,23 @@
32
35
  "./package.json": "./package.json"
33
36
  },
34
37
  "devDependencies": {
35
- "@commitlint/cli": "^20.4.2",
36
- "@commitlint/config-conventional": "^20.4.2",
38
+ "@commitlint/cli": "^21.2.2",
39
+ "@commitlint/config-conventional": "^21.2.2",
40
+ "@front-factory/eslint-config": "^2.4.2",
41
+ "@front-factory/stylelint-config": "^1.12.1",
37
42
  "@magnesium/theme": "^5.2.2",
38
- "@semantic-release/changelog": "^6.0.3",
39
- "@semantic-release/git": "^10.0.1",
43
+ "@semantic-release/changelog": "^7.0.0",
44
+ "@semantic-release/git": "^11.0.1",
40
45
  "@semantic-release/github": "^12.0.9",
41
46
  "conventional-changelog-conventionalcommits": "^9.3.1",
47
+ "eslint": "^10.10.0",
48
+ "eslint-plugin-vue": "^10.11.0",
42
49
  "husky": "^9.1.7",
43
50
  "sass": "^1.100.0",
44
51
  "semantic-release": "^25.0.9",
52
+ "stylelint": "^16.26.1",
45
53
  "typescript": "^5.9.3",
54
+ "typescript-eslint": "^8.70.0",
46
55
  "vitepress": "^2.0.0-alpha.20",
47
56
  "vue": "^3.5.34",
48
57
  "vue-tsc": "^3.2.0"
@@ -1,50 +1,57 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, onUnmounted, ref } from 'vue'
3
- import { useData } from 'vitepress'
4
- import { useLabels, useThemeOptions } from '../composables/options'
2
+ import {
3
+ computed, onMounted, onUnmounted, ref
4
+ } from 'vue';
5
+ import { useData } from 'vitepress';
6
+ import { useLabels, useThemeOptions } from '../composables/options';
5
7
 
6
- const { theme } = useData()
7
- const options = useThemeOptions()
8
- const labels = useLabels()
8
+ const { theme } = useData();
9
+ const options = useThemeOptions();
10
+ const labels = useLabels();
9
11
 
10
12
  // The visible text is the accessible name; the tooltip reuses the default theme's own option,
11
13
  // so a site that already localised its mobile return-to-top link gets this one for free.
12
- const title = computed(() => theme.value.returnToTopLabel ?? 'Return to top')
14
+ const title = computed(() => theme.value.returnToTopLabel ?? 'Return to top');
13
15
 
14
- const enabled = computed(() => options.value.backToTop !== false)
16
+ const enabled = computed(() => options.value.backToTop !== false);
15
17
 
16
- const visible = ref(false)
18
+ const visible = ref(false);
17
19
 
18
20
  function onScroll() {
19
- visible.value = window.scrollY > window.innerHeight
21
+ visible.value = window.scrollY > window.innerHeight;
20
22
  }
21
23
 
22
24
  function toTop() {
23
- window.scrollTo({ top: 0, behavior: 'smooth' })
25
+ window.scrollTo({
26
+ top: 0,
27
+ behavior: 'smooth'
28
+ });
24
29
  }
25
30
 
26
31
  onMounted(() => {
27
- onScroll()
28
- window.addEventListener('scroll', onScroll, { passive: true })
29
- })
32
+ onScroll();
33
+ window.addEventListener('scroll', onScroll, {
34
+ passive: true
35
+ });
36
+ });
30
37
 
31
- onUnmounted(() => window.removeEventListener('scroll', onScroll))
38
+ onUnmounted(() => window.removeEventListener('scroll', onScroll));
32
39
  </script>
33
40
 
34
41
  <template>
35
- <ClientOnly>
36
- <button
37
- v-if="enabled"
38
- type="button"
39
- class="ff-to-top ff-label"
40
- :class="{ 'is-visible': visible }"
41
- :tabindex="visible ? 0 : -1"
42
- :aria-hidden="!visible"
43
- :title="title"
44
- @click="toTop"
45
- >
46
- <span aria-hidden="true">&#8593;</span>
47
- <span>{{ labels.backToTop }}</span>
48
- </button>
49
- </ClientOnly>
42
+ <ClientOnly>
43
+ <button
44
+ v-if="enabled"
45
+ type="button"
46
+ class="ff-to-top ff-label"
47
+ :class="{ 'is-visible': visible }"
48
+ :tabindex="visible ? 0 : -1"
49
+ :aria-hidden="!visible"
50
+ :title="title"
51
+ @click="toTop"
52
+ >
53
+ <span aria-hidden="true">&#8593;</span>
54
+ <span>{{ labels.backToTop }}</span>
55
+ </button>
56
+ </ClientOnly>
50
57
  </template>
@@ -1,81 +1,95 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, onUnmounted, ref } from 'vue'
3
- import { useLabels, useThemeOptions } from '../composables/options'
2
+ import {
3
+ computed, onMounted, onUnmounted, ref
4
+ } from 'vue';
5
+ import { useLabels, useThemeOptions } from '../composables/options';
4
6
 
5
- const options = useThemeOptions()
6
- const labels = useLabels()
7
- const banner = computed(() => options.value.banner)
7
+ const options = useThemeOptions();
8
+ const labels = useLabels();
9
+ const banner = computed(() => options.value.banner);
8
10
 
9
- const el = ref<HTMLElement>()
10
- let observer: ResizeObserver | undefined
11
+ const el = ref<HTMLElement>();
12
+ let observer: ResizeObserver | undefined;
11
13
 
12
14
  // The class is set on <html> by an inline script injected in the head, so a dismissed banner never
13
15
  // paints. See transformHead() in config.js.
14
- const DISMISSED = 'ff-banner-dismissed'
16
+ const DISMISSED = 'ff-banner-dismissed';
15
17
 
16
18
  function height() {
17
- const root = document.documentElement
19
+ const root = document.documentElement;
18
20
 
19
21
  if (!banner.value || root.classList.contains(DISMISSED)) {
20
- root.style.removeProperty('--vp-layout-top-height')
22
+ root.style.removeProperty('--vp-layout-top-height');
21
23
 
22
- return
24
+ return;
23
25
  }
24
26
 
25
- root.style.setProperty('--vp-layout-top-height', `${el.value?.offsetHeight ?? 0}px`)
27
+ root.style.setProperty('--vp-layout-top-height', `${el.value?.offsetHeight ?? 0}px`);
26
28
  }
27
29
 
28
30
  function dismiss() {
29
- if (!banner.value) return
31
+ if (!banner.value) {
32
+ return;
33
+ }
30
34
 
31
- localStorage.setItem(`ff-banner-${banner.value.id}`, 'dismissed')
32
- document.documentElement.classList.add(DISMISSED)
33
- height()
35
+ localStorage.setItem(`ff-banner-${banner.value.id}`, 'dismissed');
36
+ document.documentElement.classList.add(DISMISSED);
37
+ height();
34
38
  }
35
39
 
36
40
  onMounted(() => {
37
- height()
41
+ height();
38
42
 
39
43
  if (el.value) {
40
- observer = new ResizeObserver(height)
41
- observer.observe(el.value)
44
+ observer = new ResizeObserver(height);
45
+ observer.observe(el.value);
42
46
  }
43
- })
47
+ });
44
48
 
45
49
  onUnmounted(() => {
46
- observer?.disconnect()
47
- document.documentElement.style.removeProperty('--vp-layout-top-height')
48
- })
50
+ observer?.disconnect();
51
+ document.documentElement.style.removeProperty('--vp-layout-top-height');
52
+ });
49
53
  </script>
50
54
 
51
55
  <template>
52
- <div
53
- v-if="banner"
54
- ref="el"
55
- class="ff-banner"
56
- :data-variant="banner.variant ?? 'ink'"
57
- :data-gradient="banner.gradient || undefined"
56
+ <div
57
+ v-if="banner"
58
+ ref="el"
59
+ class="ff-banner"
60
+ :data-variant="banner.variant ?? 'ink'"
61
+ :data-gradient="banner.gradient || undefined"
62
+ >
63
+ <component
64
+ :is="banner.link ? 'a' : 'div'"
65
+ class="ff-banner-body"
66
+ :href="banner.link"
58
67
  >
59
- <component
60
- :is="banner.link ? 'a' : 'div'"
61
- class="ff-banner-body"
62
- :href="banner.link"
63
- >
64
- <span v-if="banner.icon" class="ff-banner-icon" aria-hidden="true">{{ banner.icon }}</span>
65
- <span class="ff-banner-text" v-html="banner.text" />
66
- <span v-if="banner.link" class="ff-banner-cta">
67
- {{ banner.linkText ?? 'Read more' }}
68
- <span aria-hidden="true">&#8594;</span>
69
- </span>
70
- </component>
68
+ <span
69
+ v-if="banner.icon"
70
+ class="ff-banner-icon"
71
+ aria-hidden="true"
72
+ >{{ banner.icon }}</span>
73
+ <span
74
+ class="ff-banner-text"
75
+ v-html="banner.text"
76
+ />
77
+ <span
78
+ v-if="banner.link"
79
+ class="ff-banner-cta"
80
+ >
81
+ {{ banner.linkText ?? 'Read more' }}
82
+ <span aria-hidden="true">&#8594;</span>
83
+ </span>
84
+ </component>
71
85
 
72
- <button
73
- type="button"
74
- class="ff-banner-close"
75
- :aria-label="labels.bannerDismiss"
76
- @click="dismiss"
77
- >
78
- &#215;
79
- </button>
80
- </div>
86
+ <button
87
+ type="button"
88
+ class="ff-banner-close"
89
+ :aria-label="labels.bannerDismiss"
90
+ @click="dismiss"
91
+ >
92
+ &#215;
93
+ </button>
94
+ </div>
81
95
  </template>
@@ -1,20 +1,26 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, ref, watch } from 'vue'
3
- import { useData } from 'vitepress'
4
- import { useLayout } from '../internal'
5
- import { format, useLabels, useThemeOptions } from '../composables/options'
6
- import type { DefaultTheme } from 'vitepress/theme'
7
-
8
- const { page, frontmatter, lang } = useData()
9
- const { sidebarGroups } = useLayout()
10
- const options = useThemeOptions()
11
- const labels = useLabels()
2
+ import {
3
+ computed, nextTick, onMounted, ref, watch
4
+ } from 'vue';
5
+ import { useData } from 'vitepress';
6
+ import { useLayout } from '../internal';
7
+ import {
8
+ format, useLabels, useThemeOptions
9
+ } from '../composables/options';
10
+ import type { DefaultTheme } from 'vitepress/theme';
11
+
12
+ const { page, frontmatter, lang } = useData();
13
+ const { sidebarGroups } = useLayout();
14
+ const options = useThemeOptions();
15
+ const labels = useLabels();
12
16
 
13
17
  const meta = computed(() => {
14
- if (options.value.meta === false || frontmatter.value.docMeta === false) return null
18
+ if (options.value.meta === false || frontmatter.value.docMeta === false) {
19
+ return null;
20
+ }
15
21
 
16
- return options.value.meta ?? {}
17
- })
22
+ return options.value.meta ?? {};
23
+ });
18
24
 
19
25
  // --------------------------------------------------------------------------------------------- //
20
26
  // Section, read from the sidebar the site already declares
@@ -27,86 +33,132 @@ function normalize(path: string) {
27
33
  return path
28
34
  .replace(/^\//, '')
29
35
  .replace(/(index)?\.(md|html)$/, '')
30
- .replace(/\/$/, '')
36
+ .replace(/\/$/, '');
31
37
  }
32
38
 
33
39
  function contains(items: DefaultTheme.SidebarItem[], path: string): boolean {
34
40
  return items.some(
35
41
  (item) =>
36
42
  (item.link && normalize(item.link) === path) || contains(item.items ?? [], path)
37
- )
43
+ );
38
44
  }
39
45
 
40
46
  const section = computed(() => {
41
- if (!meta.value || meta.value.section === false) return null
42
- if (frontmatter.value.section) return String(frontmatter.value.section)
47
+ if (!meta.value || meta.value.section === false) {
48
+ return null;
49
+ }
50
+
51
+ if (frontmatter.value.section) {
52
+ return String(frontmatter.value.section);
53
+ }
43
54
 
44
- const path = normalize(page.value.relativePath)
55
+ const path = normalize(page.value.relativePath);
45
56
 
46
- return sidebarGroups.value.find((group) => contains(group.items ?? [], path))?.text ?? null
47
- })
57
+ return sidebarGroups.value.find((group) => contains(group.items ?? [], path))?.text ?? null;
58
+ });
48
59
 
49
60
  // --------------------------------------------------------------------------------------------- //
50
61
  // Reading time, measured on the rendered page
51
62
  // --------------------------------------------------------------------------------------------- //
52
63
 
53
- const words = ref(0)
64
+ const words = ref(0);
54
65
 
55
66
  function measure() {
56
67
  words.value =
57
68
  document.querySelector('.vp-doc')?.textContent?.trim().split(/\s+/).filter(Boolean)
58
- .length ?? 0
69
+ .length ?? 0;
59
70
  }
60
71
 
61
- onMounted(() => nextTick(measure))
62
- watch(() => page.value.relativePath, () => nextTick(measure))
72
+ onMounted(() => nextTick(measure));
73
+ watch(() => page.value.relativePath, () => nextTick(measure));
63
74
 
64
75
  const minutes = computed(() => {
65
- if (!meta.value || meta.value.readingTime === false || !words.value) return null
76
+ if (!meta.value || meta.value.readingTime === false || !words.value) {
77
+ return null;
78
+ }
66
79
 
67
- return Math.max(1, Math.round(words.value / (meta.value.wordsPerMinute ?? 200)))
68
- })
80
+ return Math.max(1, Math.round(words.value / (meta.value.wordsPerMinute ?? 200)));
81
+ });
69
82
 
70
83
  // --------------------------------------------------------------------------------------------- //
71
84
  // Last updated
72
85
  // --------------------------------------------------------------------------------------------- //
73
86
 
74
87
  const units: [Intl.RelativeTimeFormatUnit, number][] = [
75
- ['year', 31536000000],
76
- ['month', 2592000000],
77
- ['week', 604800000],
78
- ['day', 86400000],
79
- ['hour', 3600000],
80
- ['minute', 60000]
81
- ]
88
+ [
89
+ 'year',
90
+ 31536000000
91
+ ],
92
+ [
93
+ 'month',
94
+ 2592000000
95
+ ],
96
+ [
97
+ 'week',
98
+ 604800000
99
+ ],
100
+ [
101
+ 'day',
102
+ 86400000
103
+ ],
104
+ [
105
+ 'hour',
106
+ 3600000
107
+ ],
108
+ [
109
+ 'minute',
110
+ 60000
111
+ ]
112
+ ];
82
113
 
83
114
  const updated = computed(() => {
84
- if (!meta.value || meta.value.lastUpdated === false || !page.value.lastUpdated) return null
85
-
86
- const elapsed = page.value.lastUpdated - Date.now()
87
- const relative = new Intl.RelativeTimeFormat(lang.value, { numeric: 'auto' })
115
+ if (!meta.value || meta.value.lastUpdated === false || !page.value.lastUpdated) {
116
+ return null;
117
+ }
88
118
 
89
- for (const [unit, ms] of units) {
90
- if (Math.abs(elapsed) >= ms) return relative.format(Math.round(elapsed / ms), unit)
119
+ const elapsed = page.value.lastUpdated - Date.now();
120
+ const relative = new Intl.RelativeTimeFormat(lang.value, {
121
+ numeric: 'auto'
122
+ });
123
+
124
+ for (const [
125
+ unit,
126
+ ms
127
+ ] of units) {
128
+ if (Math.abs(elapsed) >= ms) {
129
+ return relative.format(Math.round(elapsed / ms), unit);
130
+ }
91
131
  }
92
132
 
93
- return relative.format(0, 'minute')
94
- })
133
+ return relative.format(0, 'minute');
134
+ });
95
135
 
96
- const hidden = computed(() => !meta.value || frontmatter.value.layout === 'home')
136
+ const hidden = computed(() => !meta.value || frontmatter.value.layout === 'home');
97
137
  </script>
98
138
 
99
139
  <template>
100
- <div v-if="!hidden" class="ff-doc-meta ff-label">
101
- <span v-if="section" class="ff-doc-meta-item">{{ section }}</span>
102
-
103
- <ClientOnly>
104
- <span v-if="minutes" class="ff-doc-meta-item">
105
- {{ format(labels.readingTime, minutes) }}
106
- </span>
107
- <span v-if="updated" class="ff-doc-meta-item">
108
- {{ format(labels.lastUpdated, updated) }}
109
- </span>
110
- </ClientOnly>
111
- </div>
140
+ <div
141
+ v-if="!hidden"
142
+ class="ff-doc-meta ff-label"
143
+ >
144
+ <span
145
+ v-if="section"
146
+ class="ff-doc-meta-item"
147
+ >{{ section }}</span>
148
+
149
+ <ClientOnly>
150
+ <span
151
+ v-if="minutes"
152
+ class="ff-doc-meta-item"
153
+ >
154
+ {{ format(labels.readingTime, minutes) }}
155
+ </span>
156
+ <span
157
+ v-if="updated"
158
+ class="ff-doc-meta-item"
159
+ >
160
+ {{ format(labels.lastUpdated, updated) }}
161
+ </span>
162
+ </ClientOnly>
163
+ </div>
112
164
  </template>
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { VPImage, VPLink } from '../internal'
3
- import type { DefaultTheme } from 'vitepress/theme'
2
+ import { VPImage, VPLink } from '../internal';
3
+ import type { DefaultTheme } from 'vitepress/theme';
4
4
 
5
5
  defineProps<{
6
6
  icon?: DefaultTheme.FeatureIcon
@@ -10,35 +10,67 @@ defineProps<{
10
10
  linkText?: string
11
11
  rel?: string
12
12
  target?: string
13
- }>()
13
+ }>();
14
14
  </script>
15
15
 
16
16
  <template>
17
- <VPLink
18
- class="VPFeature ff-feature"
19
- :href="link"
20
- :rel="rel"
21
- :target="target"
22
- :no-icon="true"
23
- :tag="link ? 'a' : 'div'"
24
- >
25
- <span class="ff-feature-index" aria-hidden="true" />
17
+ <VPLink
18
+ class="VPFeature ff-feature"
19
+ :href="link"
20
+ :rel="rel"
21
+ :target="target"
22
+ :no-icon="true"
23
+ :tag="link ? 'a' : 'div'"
24
+ >
25
+ <span
26
+ class="ff-feature-index"
27
+ aria-hidden="true"
28
+ />
26
29
 
27
- <div v-if="typeof icon === 'object'" class="ff-feature-icon">
28
- <VPImage :image="icon" :alt="icon.alt" :height="icon.height || 28" :width="icon.width || 28" />
29
- </div>
30
- <div v-else-if="icon" class="ff-feature-icon" v-html="icon" />
30
+ <div
31
+ v-if="typeof icon === 'object'"
32
+ class="ff-feature-icon"
33
+ >
34
+ <VPImage
35
+ :image="icon"
36
+ :alt="icon.alt"
37
+ :height="icon.height || 28"
38
+ :width="icon.width || 28"
39
+ />
40
+ </div>
41
+ <div
42
+ v-else-if="icon"
43
+ class="ff-feature-icon"
44
+ v-html="icon"
45
+ />
31
46
 
32
- <h2 class="ff-feature-title" v-html="title" />
47
+ <h2
48
+ class="ff-feature-title"
49
+ v-html="title"
50
+ />
33
51
 
34
- <ul v-if="Array.isArray(details)" class="ff-feature-details">
35
- <li v-for="item in details" :key="item" v-html="item" />
36
- </ul>
37
- <p v-else-if="details" class="ff-feature-details" v-html="details" />
52
+ <ul
53
+ v-if="Array.isArray(details)"
54
+ class="ff-feature-details"
55
+ >
56
+ <li
57
+ v-for="item in details"
58
+ :key="item"
59
+ v-html="item"
60
+ />
61
+ </ul>
62
+ <p
63
+ v-else-if="details"
64
+ class="ff-feature-details"
65
+ v-html="details"
66
+ />
38
67
 
39
- <span v-if="linkText" class="ff-feature-link ff-label">
40
- {{ linkText }}
41
- <span aria-hidden="true">&#8594;</span>
42
- </span>
43
- </VPLink>
68
+ <span
69
+ v-if="linkText"
70
+ class="ff-feature-link ff-label"
71
+ >
72
+ {{ linkText }}
73
+ <span aria-hidden="true">&#8594;</span>
74
+ </span>
75
+ </VPLink>
44
76
  </template>