Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional default language directory #68

Merged
merged 5 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ The directory structure of a minimal Docus project is the following:

```bash
| content/
---| en/
-----| index.md
---| index.md
---| settings.json
| static/
---| icon.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ As explained in the [Nuxt config](/usage/configuration#nuxt) section, we use `de

## Routing

Each markdown page in the `content/{locale}/` directory will become a page and will be listed in the left navigation.
Each markdown page in the `content/` directory will become a page and will be listed in the left navigation.

> You can also put your markdown files in subdirectories to generate sub-routes.

Expand All @@ -90,10 +90,9 @@ Each markdown page in the `content/{locale}/` directory will become a page and w

```
content/
en/
examples/
basic-usage.md
setup.md
examples/
basic-usage.md
setup.md
```

</code-block>
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions theme/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default function docusModule () {
const regexp = new RegExp(`^/(${options.i18n.locales.map(locale => locale.code).join('|')})`, 'gi')
const { dir, slug, category } = document
const _dir = dir.replace(regexp, '')
const _language = dir.replace(_dir, '')
const _language = dir.replace(_dir, '').replace(/\//, '') || options.i18n.defaultLocale
const _category = category && typeof category === 'string' ? category : ''
const _to = `${_dir}/${slug}`
const _to = `${_dir}/${slug}`.replace(/\/+/, '/')
const position = generatePosition(_to, document)

document.slug = generateSlug(slug)
Expand Down
5 changes: 3 additions & 2 deletions theme/pages/_.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export default {
}
},
async asyncData ({ $content, store, app, params, error }) {
const language = `/${app.i18n.locale}`
const language = app.i18n.locale
const to = `/${params.pathMatch || ''}`
const [document] = await $content({ deep: true }).where({ language, to }).fetch()
if (!document) {
return error({ statusCode: 404, message: 'Page not found' })
}

const [prev, next] = await $content(app.i18n.locale, { deep: true })
const [prev, next] = await $content({ deep: true })
.where({ language })
.only(['title', 'slug', 'to'])
.sortBy('position', 'asc')
.surround(document.slug, { before: 1, after: 1 })
Expand Down
2 changes: 1 addition & 1 deletion theme/plugins/docus.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default async function ({ app, $content, $config, nuxtState = {}, beforeN
if (process.dev === false && this.categories[app.i18n.locale]) {
return
}
const docs = await $content(app.i18n.locale, { deep: true }).only(['title', 'menuTitle', 'category', 'slug', 'version', 'to']).sortBy('position', 'asc').fetch()
const docs = await $content({ deep: true }).where({ language: app.i18n.locale }).only(['title', 'menuTitle', 'category', 'slug', 'version', 'to']).sortBy('position', 'asc').fetch()
if (this.lastRelease) {
docs.push({ slug: 'releases', title: 'Releases', category: 'Community', to: '/releases' })
}
Expand Down