@sewadah/selaras-docs 1.4.0 → 1.4.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/CHANGELOG.md +29 -0
- package/README.md +3 -0
- package/app/composables/useDocsLocale.ts +8 -1
- package/app/composables/useDocsNavigation.ts +7 -4
- package/app/pages/[...slug].vue +2 -2
- package/app/utils/docs-locale.ts +21 -0
- package/package.json +2 -2
- package/types.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.4.2
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.1...selaras-docs-v1.4.2)
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **fix(docs):** sync active locale with route ([0b8599d](https://github.com/sewadahapp/selaras/commit/0b8599daff9df6b358c5be5815e31aab3722e2f2))
|
|
10
|
+
|
|
11
|
+
### 🤖 Other changes
|
|
12
|
+
|
|
13
|
+
- Merge pull request #36 from sewadahapp/fix/docs-locale-route-state ([15e5002](https://github.com/sewadahapp/selaras/commit/15e50021f9db28bc1d47b6cd0c7ff404388d18dd))
|
|
14
|
+
|
|
15
|
+
Published against `@sewadah/selaras` ^1.3.0.
|
|
16
|
+
|
|
17
|
+
## v1.4.1
|
|
18
|
+
|
|
19
|
+
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.0...selaras-docs-v1.4.1)
|
|
20
|
+
|
|
21
|
+
### 🩹 Fixes
|
|
22
|
+
|
|
23
|
+
- **fix(docs):** respect consumer site URLs ([27b5e15](https://github.com/sewadahapp/selaras/commit/27b5e15da601c2b3904c7f4b87466fe93e6d9679))
|
|
24
|
+
- **fix(docs):** restore localized sidebar navigation ([541d7a4](https://github.com/sewadahapp/selaras/commit/541d7a4627c66a2e0079d03aa0b7d0b08872084f))
|
|
25
|
+
|
|
26
|
+
### 🤖 Other changes
|
|
27
|
+
|
|
28
|
+
- Merge pull request #34 from sewadahapp/fix/docs-indonesian-sidebar ([b9fe143](https://github.com/sewadahapp/selaras/commit/b9fe143253de9ee89f2e0631f89df9606911eb56))
|
|
29
|
+
|
|
30
|
+
Published against `@sewadah/selaras` ^1.2.0.
|
|
31
|
+
|
|
3
32
|
## v1.4.0
|
|
4
33
|
|
|
5
34
|
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.3.3...selaras-docs-v1.4.0)
|
package/README.md
CHANGED
|
@@ -111,6 +111,9 @@ export default defineAppConfig({
|
|
|
111
111
|
})
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
Set `selarasDocs.site.url` to your public site origin to generate canonical and
|
|
115
|
+
Open Graph URLs. When omitted, the layer leaves these URLs to your app.
|
|
116
|
+
|
|
114
117
|
Folder navigation can be configured with a `.navigation.yml` file alongside
|
|
115
118
|
the Markdown pages in that folder:
|
|
116
119
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SelarasDocsLocaleOption } from '../../types'
|
|
2
|
+
import { resolveDocsLocale } from '../utils/docs-locale'
|
|
2
3
|
|
|
3
4
|
interface DocsI18nRuntime {
|
|
4
5
|
locale?: string | { value?: string }
|
|
@@ -30,10 +31,16 @@ export function useDocsLocale() {
|
|
|
30
31
|
const configured = computed(() => appConfig.selarasDocs?.i18n?.locales ?? [])
|
|
31
32
|
const locales = computed<SelarasDocsLocaleOption[]>(() => configured.value.length ? configured.value : fallbackLocales)
|
|
32
33
|
const defaultLocale = computed(() => appConfig.selarasDocs?.i18n?.defaultLocale ?? locales.value[0]?.code ?? 'en')
|
|
34
|
+
const route = useRoute()
|
|
33
35
|
const i18n = (nuxtApp as unknown as { $i18n?: DocsI18nRuntime }).$i18n
|
|
34
36
|
const locale = computed(() => {
|
|
35
37
|
const active = i18n?.locale
|
|
36
|
-
return (
|
|
38
|
+
return resolveDocsLocale(
|
|
39
|
+
route.path,
|
|
40
|
+
(typeof active === 'string' ? active : active?.value),
|
|
41
|
+
locales.value,
|
|
42
|
+
defaultLocale.value,
|
|
43
|
+
)
|
|
37
44
|
})
|
|
38
45
|
const localeOption = computed(() => locales.value.find(option => option.code === locale.value) ?? locales.value[0]!)
|
|
39
46
|
const hasLocaleSwitching = computed(() => locales.value.length > 1 && typeof i18n?.setLocale === 'function')
|
|
@@ -10,7 +10,10 @@ export function useDocsNavigation() {
|
|
|
10
10
|
.map(option => option.code)
|
|
11
11
|
.filter(code => code !== defaultLocale.value))
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// Prerendering shares results by key, so each locale needs its own tree.
|
|
14
|
+
return useAsyncData(() => `selaras-docs-navigation:${defaultLocale.value}:${locale.value}`, async () => {
|
|
15
|
+
const activeLocale = locale.value
|
|
16
|
+
const activeDefaultLocale = defaultLocale.value
|
|
14
17
|
const tree = await queryCollectionNavigation('docs', ['order', 'icon', 'collapse', 'navBadges'])
|
|
15
18
|
.order('order', 'ASC')
|
|
16
19
|
|
|
@@ -19,7 +22,7 @@ export function useDocsNavigation() {
|
|
|
19
22
|
// contribute their own titles; untranslated pages keep the source title.
|
|
20
23
|
let defaultTree = withoutDocsLocaleFolders(tree as DocsNavigationNode[], localeFolders.value)
|
|
21
24
|
|
|
22
|
-
if (
|
|
25
|
+
if (activeLocale !== activeDefaultLocale && translatedFolder.value) {
|
|
23
26
|
const translated = await queryCollection('docs')
|
|
24
27
|
.where('path', 'LIKE', `/${translatedFolder.value}/%`)
|
|
25
28
|
.select('path', 'title')
|
|
@@ -57,10 +60,10 @@ export function useDocsNavigation() {
|
|
|
57
60
|
|
|
58
61
|
const localize = (items: DocsNavigationNode[]): DocsNavigationNode[] => items.map(item => ({
|
|
59
62
|
...item,
|
|
60
|
-
path: docsLocalizedRoutePath(item.path,
|
|
63
|
+
path: docsLocalizedRoutePath(item.path, activeLocale, activeDefaultLocale),
|
|
61
64
|
...(item.children ? { children: localize(item.children) } : {}),
|
|
62
65
|
}))
|
|
63
66
|
|
|
64
67
|
return localize(visit(defaultTree, excluded.size > 0))
|
|
65
|
-
}
|
|
68
|
+
})
|
|
66
69
|
}
|
package/app/pages/[...slug].vue
CHANGED
|
@@ -8,7 +8,7 @@ import ProseH5 from '@sewadah/selaras/components/ProseH5.vue'
|
|
|
8
8
|
import ProseH6 from '@sewadah/selaras/components/ProseH6.vue'
|
|
9
9
|
import ProsePre from '@sewadah/selaras/components/ProsePre.vue'
|
|
10
10
|
import { docsDefaultContentPath, docsLocalizedRoutePath } from '../utils/content-path'
|
|
11
|
-
import { docsCanonicalUrl
|
|
11
|
+
import { docsCanonicalUrl } from '../utils/seo'
|
|
12
12
|
|
|
13
13
|
const route = useRoute()
|
|
14
14
|
const appConfig = useAppConfig()
|
|
@@ -36,7 +36,7 @@ async function retryPage() {
|
|
|
36
36
|
|
|
37
37
|
definePageMeta({ layout: 'selaras-docs' })
|
|
38
38
|
const { locale, defaultLocale, locales, localeOption } = useDocsLocale()
|
|
39
|
-
const siteUrl = appConfig.selarasDocs?.site?.url
|
|
39
|
+
const siteUrl = appConfig.selarasDocs?.site?.url
|
|
40
40
|
const config = useRuntimeConfig()
|
|
41
41
|
const defaultRoutePath = computed(() => docsDefaultContentPath(contentPath.value, locale.value, defaultLocale.value))
|
|
42
42
|
const translatedPage = computed(() => locale.value !== defaultLocale.value && contentPath.value.startsWith(`/${locale.value}/`))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface DocsLocaleCode {
|
|
2
|
+
code: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Prefer an explicit locale prefix in the current route over the i18n
|
|
7
|
+
* composer's active locale. On a root locale-detection redirect, SSR may
|
|
8
|
+
* render the prefixed locale before the client composer has synchronized.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveDocsLocale(
|
|
11
|
+
routePath: string,
|
|
12
|
+
activeLocale: string | undefined,
|
|
13
|
+
locales: readonly DocsLocaleCode[],
|
|
14
|
+
defaultLocale: string,
|
|
15
|
+
) {
|
|
16
|
+
const pathname = routePath.split(/[?#]/, 1)[0] || '/'
|
|
17
|
+
const routeLocale = locales.find(({ code }) => code !== defaultLocale
|
|
18
|
+
&& (pathname === `/${code}` || pathname.startsWith(`/${code}/`)))?.code
|
|
19
|
+
|
|
20
|
+
return routeLocale ?? activeLocale ?? defaultLocale
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sewadah/selaras-docs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.2",
|
|
5
5
|
"description": "Nuxt Content documentation layer for Selaras",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@nuxt/content": "^3.16.0",
|
|
35
35
|
"@nuxt/kit": "^4.5.2",
|
|
36
|
-
"@sewadah/selaras": "^1.
|
|
36
|
+
"@sewadah/selaras": "^1.3.0",
|
|
37
37
|
"tailwindcss": "^4.3.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/types.d.ts
CHANGED
|
@@ -126,6 +126,7 @@ export interface SelarasDocsAppConfig {
|
|
|
126
126
|
description?: string
|
|
127
127
|
/** Applied to browser titles; `%s` is replaced with the current page title. */
|
|
128
128
|
titleTemplate?: string
|
|
129
|
+
/** Public site origin for canonical and Open Graph URLs. These URL tags are omitted when unset. */
|
|
129
130
|
url?: string
|
|
130
131
|
/** Shown in the header and footer. A `/`-rooted path is served from `public/` under the app's base URL. */
|
|
131
132
|
logo?: string | SelarasDocsLogo
|