Skip to content

Commit c77cd1d

Browse files
committed
fix: sidebar and copy
1 parent 9800794 commit c77cd1d

File tree

9 files changed

+80
-19
lines changed

9 files changed

+80
-19
lines changed

packages/nimiq-icons/src/flags/icons.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@
12681268
"body": "<mask id=\"nimiq-flags-zw-hexagon-pbk987\" width=\"32\" height=\"28\" x=\"0\" y=\"2\" maskUnits=\"userSpaceOnUse\" style=\"mask-type:alpha\"><path fill=\"#fff\" d=\"M31.15 14.71 24.707 3.54a2.58 2.58 0 00-2.234-1.29H9.582c-.92 0-1.77.49-2.23 1.29L.907 14.71c-.46.8-.46 1.78 0 2.58l6.445 11.17c.46.8 1.31 1.29 2.23 1.29h12.89c.92 0 1.77-.49 2.23-1.29l6.445-11.17c.464-.8.464-1.78.004-2.58\"/></mask><g fill=\"none\"><g mask=\"url(#nimiq-flags-zw-hexagon-pbk987)\"><path fill=\"#6DA544\" d=\"M1.962 0H32v32H1.962z\"/><path fill=\"#FFDA44\" d=\"M3.613 4.581H32v4.582l-4.069 6.875 4.07 6.875v4.58H3.612z\"/><path fill=\"#D80027\" d=\"M8.25 9.162H32v4.582l-1.687 2.25L32 18.325v4.581H8.25z\"/><path fill=\"#EEE\" d=\"M0 0v32l17.488-16z\"/><path fill=\"#D80027\" d=\"m6.437 11.825 1.032 3.188h3.35l-2.713 1.975 1.038 3.187-2.713-1.969-2.712 1.969 1.037-3.187-2.712-1.976h3.35z\"/><path fill=\"#FFDA44\" d=\"m9.281 16.263-2.7-.957-.212-1.937a1.044 1.044 0 10-2.032.475l-.75.756h1.344c0 1.4-1.044 1.4-1.044 2.794l.575 1.387h3.482l.58-1.387q.086-.198.107-.413c.5-.2.65-.719.65-.719\"/><path fill=\"#333\" d=\"m1.963 0 13.75 13.75H32v4.575H15.638L1.962 32H0l16-16L0 0z\"/><path fill=\"url(#nimiq-flags-zw-hexagon-pbk987)\" d=\"M31.15 14.71 24.707 3.54a2.58 2.58 0 00-2.234-1.29H9.582c-.92 0-1.77.49-2.23 1.29L.907 14.71c-.46.8-.46 1.78 0 2.58l6.445 11.17c.46.8 1.31 1.29 2.23 1.29h12.89c.92 0 1.77-.49 2.23-1.29l6.445-11.17c.464-.8.464-1.78.004-2.58\"/></g><defs><radialGradient id=\"nimiq-flags-zw-hexagon-pbk987\" cx=\"0\" cy=\"0\" r=\"1\" gradientTransform=\"matrix(30.943 0 0 30.9452 23.829 29.395)\" gradientUnits=\"userSpaceOnUse\"><stop stop-color=\"#1D1D1B\" stop-opacity=\".3\"/><stop offset=\"1\" stop-color=\"#E9B213\" stop-opacity=\"0\"/></radialGradient></defs></g>"
12691269
}
12701270
},
1271-
"lastModified": 1758097768,
1271+
"lastModified": 1758100113,
12721272
"width": 32,
12731273
"height": 32
12741274
}

packages/nimiq-icons/src/flags/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"prefix": "nimiq-flags",
33
"name": "nimiq-flags",
44
"total": 422,
5-
"version": "1.0.0-beta.84",
5+
"version": "1.0.0-beta.85",
66
"author": {
77
"name": "onmax",
88
"url": "https://github.com/onmax"

packages/nimiq-icons/src/flags/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nimiq-flags",
33
"description": "The Nimiq Flags as an iconify icon set.",
44
"version": "1.0.0-beta.85",
5-
"iconSetVersion": "1.0.0-beta.84",
5+
"iconSetVersion": "1.0.0-beta.85",
66
"main": "index.js",
77
"module": "index.mjs",
88
"types": "index.d.ts",

packages/nimiq-icons/src/icons/icons.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@
15861586
"hidden": true
15871587
}
15881588
},
1589-
"lastModified": 1758097768,
1589+
"lastModified": 1758100113,
15901590
"width": 12,
15911591
"height": 12
15921592
}

packages/nimiq-icons/src/icons/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"prefix": "nimiq",
33
"name": "nimiq-icons",
44
"total": 84,
5-
"version": "1.0.0-beta.84",
5+
"version": "1.0.0-beta.85",
66
"author": {
77
"name": "onmax",
88
"url": "https://github.com/onmax"

packages/nimiq-icons/src/icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nimiq-icons",
33
"description": "The Nimiq Icons as an iconify icon set.",
44
"version": "1.0.0-beta.85",
5-
"iconSetVersion": "1.0.0-beta.84",
5+
"iconSetVersion": "1.0.0-beta.85",
66
"main": "index.js",
77
"module": "index.mjs",
88
"types": "index.d.ts",

packages/nimiq-vitepress-theme/src/composables/useHeaderScroll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function useHeaderScroll(threshold = 10, hideDelay = 100) {
1616
let hideTimeout: ReturnType<typeof setTimeout> | null = null
1717

1818
const handleScroll = () => {
19-
const currentScrollY = window.scrollY
19+
const currentScrollY = typeof window !== 'undefined' ? window.scrollY : 0
2020
scrollY.value = currentScrollY
2121

2222
// Don't hide header when at the very top

packages/nimiq-vitepress-theme/src/composables/useSourceCode.ts

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { useClipboard } from '@vueuse/core'
22
import { join } from 'pathe'
33
import { useData } from 'vitepress'
4-
import { computed } from 'vue'
4+
import { computed, ref } from 'vue'
55
import { toast } from 'vue-sonner'
66
import { useChangelog } from './useChangelog'
77

88
export function useSourceCode() {
99
const { page, frontmatter } = useData()
1010
const { repoURL } = useChangelog()
11-
const { copy, copied, isSupported } = useClipboard()
11+
12+
// Use a safer approach for SSR compatibility
13+
const clipboardResult = typeof window !== 'undefined'
14+
? useClipboard()
15+
: { copy: async () => {}, copied: ref(false), isSupported: ref(false) }
16+
const { copy, copied, isSupported } = clipboardResult
1217

1318
const showSourceCode = computed(() => {
1419
if (!isSupported.value)
@@ -97,14 +102,65 @@ export function useSourceCode() {
97102
.replace('/blob/', '/')
98103
}
99104

100-
const response = await fetch(rawUrl)
101-
if (!response.ok) {
102-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
105+
// Generate multiple URL variations to try
106+
const urlsToTry: string[] = []
107+
const filePath = page.value.filePath
108+
109+
if (repoURL.value) {
110+
const baseRawUrl = repoURL.value
111+
.replace('github.com', 'raw.githubusercontent.com')
112+
.replace(/\/$/, '')
113+
114+
// Try different path combinations
115+
const pathVariations = [
116+
getRepoFilePath.value, // Current computed path
117+
filePath, // Original file path without modifications
118+
filePath.startsWith('/') ? filePath.slice(1) : filePath, // Remove leading slash
119+
]
120+
121+
// If current path has docs/, also try without it
122+
if (getRepoFilePath.value.includes('docs/')) {
123+
pathVariations.push(getRepoFilePath.value.replace('docs/', ''))
124+
}
125+
126+
// If current path doesn't have docs/, also try with it
127+
if (!getRepoFilePath.value.includes('docs/')) {
128+
pathVariations.push(join('docs', getRepoFilePath.value))
129+
}
130+
131+
// Generate full URLs for each path variation
132+
pathVariations.forEach((path) => {
133+
const cleanPath = path.startsWith('/') ? path.slice(1) : path
134+
urlsToTry.push(`${baseRawUrl}/main/${cleanPath}`)
135+
})
136+
}
137+
else {
138+
// Fallback to original logic if no repoURL
139+
urlsToTry.push(rawUrl)
140+
}
141+
142+
// Remove duplicates
143+
const uniqueUrls = [...new Set(urlsToTry)]
144+
145+
let lastError: Error | null = null
146+
147+
for (const url of uniqueUrls) {
148+
try {
149+
const response = await fetch(url)
150+
if (response.ok) {
151+
const content = await response.text()
152+
await copy(content)
153+
toast.success('Page content copied to clipboard')
154+
return
155+
}
156+
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`)
157+
}
158+
catch (error) {
159+
lastError = error as Error
160+
}
103161
}
104162

105-
const content = await response.text()
106-
await copy(content)
107-
toast.success('Page content copied to clipboard')
163+
throw lastError || new Error('All URL attempts failed')
108164
}
109165
catch (error) {
110166
console.error('Failed to copy markdown content:', error)
@@ -115,8 +171,13 @@ export function useSourceCode() {
115171

116172
const copyMarkdownLink = async () => {
117173
try {
174+
if (typeof window === 'undefined') {
175+
toast.error('Copy functionality not available during server-side rendering')
176+
return
177+
}
178+
118179
const pageTitle = page.value.title || document.title || 'Documentation Page'
119-
const currentURL = typeof window !== 'undefined' ? window.location.href : ''
180+
const currentURL = window.location.href
120181
const markdownLink = `[${pageTitle}](${currentURL})`
121182

122183
await copy(markdownLink)

packages/nimiq-vitepress-theme/src/layout/Sidebar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function openAccordionInitialState(items: NimiqVitepressSidebar['items'][number]
6767
<CommandMenu v-if="search" f-mt-sm />
6868

6969
<CollapsibleRoot v-model:open="submoduleNavigatorOpen" w-full f-mt-sm>
70-
<CollapsibleTrigger bg-transparent w-full relative group ring="1.5 neutral-300" rounded="6 reka-open:b-0" transition-border-radius of-clip>
70+
<CollapsibleTrigger bg-transparent w-full relative group outline="~ 1.5 neutral-300" rounded="6 reka-open:b-0" transition-border-radius of-clip>
7171
<ModulePill v-if="currentDocModule" :item="currentDocModule" component="div" />
7272
<div v-else f-py-sm>
7373
Go to module
@@ -76,7 +76,7 @@ function openAccordionInitialState(items: NimiqVitepressSidebar['items'][number]
7676
</CollapsibleTrigger>
7777

7878
<CollapsibleContent of-hidden data-open:shadow w-full mt-0>
79-
<div absolute z-90 bg-neutral-100 outline="~ 1.5 offset--1.5 neutral-300" rounded-b-6 data-open:animate-slide-down data-closed:animate-slide-up w="[calc(100%-30px)]" shadow>
79+
<div absolute z-90 bg-neutral-100 outline="~ 1.5 neutral-300" rounded-b-6 data-open:animate-slide-down data-closed:animate-slide-up w="[calc(100%-30px)]" shadow>
8080
<ModulePill v-for="item in visibleModules.filter(m => m !== currentDocModule)" :key="item.text" :item="item" component="a" @click="submoduleNavigatorOpen = false" />
8181
</div>
8282
</CollapsibleContent>
@@ -93,7 +93,7 @@ function openAccordionInitialState(items: NimiqVitepressSidebar['items'][number]
9393
<span flex-1 v-html="renderMarkdown(text)" />
9494
</a>
9595
</DefineSidebarItem>
96-
<ScrollAreaRoot relative of-hidden bg-neutral-100 var:scrollbar-size:10px as="nav" flex-1 f-p="sm md:xs" v-bind="$attrs">
96+
<ScrollAreaRoot relative of-hidden bg-neutral-100 var:scrollbar-size:10px as="nav" flex-1 f-px="sm md:xs" v-bind="$attrs">
9797
<div absolute top-0 z-2 w-full h-24 bg-gradient-to-t from-transparent to-neutral-100 />
9898
<ScrollAreaViewport size-full f-pt-xs as="ul">
9999
<li v-for="item in currentDocModule.sidebar" :key="item.label" f-pb-xs>

0 commit comments

Comments
 (0)