Skip to content

Commit

Permalink
feat: optional default language directory (#68)
Browse files Browse the repository at this point in the history
* feat: optional default language directory

* clean usage

* update docs

* fix fetchCategories
  • Loading branch information
farnabaz authored Feb 17, 2021
1 parent f6104b2 commit 7bcd794
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 12 deletions.
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
File renamed without changes.
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.
File renamed without changes.
File renamed without changes.
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

1 comment on commit 7bcd794

@vercel
Copy link

@vercel vercel bot commented on 7bcd794 Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.