Skip to content

Commit

Permalink
fix: edit this page (#356)
Browse files Browse the repository at this point in the history
* fix: edit this page

* fix: cleanup

* 🔥 (core) remove contentDir injection

* ♻️ (i18n) update contentDir reference

* ✨ (theme) update page bottom

* ♻️ (docus) general cleanup

* 🏷️ (types) update DocusSettings

Co-authored-by: Yaël GUILLOUX <[email protected]>
  • Loading branch information
bdrtsky and Tahul authored May 31, 2021
1 parent 5ca9d8a commit 23571b1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/core/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export default <Module>async function docusModule() {
// Inject Docus theme as ~docus
options.alias['~docus'] = resolve(__dirname, 'runtime')

// Inject content dir in private runtime config
const contentDir = options.dir.pages || 'pages'
options.publicRuntimeConfig.contentDir = contentDir

// extend parser options
const parserOptions: Partial<ParserOptions> = { markdown: {} }
await nuxt.callHook('docus:parserOptions', parserOptions)
Expand Down Expand Up @@ -188,8 +184,12 @@ export default <Module>async function docusModule() {
options.watch.push(pagesDirPath)
}
})

nuxt.callHook('docus:storage:ready')

// Watch Docus while DOCUS_DEV is set
if (process.env.DOCUS_DEV) options.watch.push(resolve(__dirname, '../'))

nuxt.hook('close', () => {
destroyHooks()
destroyDB()
Expand Down
20 changes: 7 additions & 13 deletions src/defaultTheme/components/organisms/PageBottom.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<template>
<div v-if="link" class="flex flex-col justify-between mt-8 mb-4 sm:flex-row">
<a
:href="link"
target="_blank"
rel="noopener"
class="flex items-center mb-2 text-sm sm:mb-0 font-base hover:underline dark:text-gray-400"
>
<div v-if="link" class="flex flex-col justify-between text-gray-500 dark:text-gray-500 mt-8 mb-4 sm:flex-row">
<a :href="link" target="_blank" rel="noopener" class="flex items-center mb-2 text-sm sm:mb-0 hover:underline">
<IconEdit class="w-3 h-3 mr-1" />
<span>
{{ $t('article.github') }}
</span>
</a>

<span class="flex items-center text-sm text-gray-500 font-base dark:text-gray-400">
<span class="flex items-center text-sm">
{{ $t('article.updatedAt') }} {{ $d(Date.parse(page.updatedAt), 'long') }}
</span>
</div>
Expand All @@ -29,19 +24,18 @@ export default defineComponent({
}
},
setup(props) {
const { $docus, $config } = useContext()
const { $docus } = useContext()
const settings = computed(() => $docus.settings)
const { value: settings } = computed(() => $docus.settings)
const link = computed(() => {
if (!settings.value.github) return
return [
$docus.repoUrl,
$docus.repoUrl.value,
'edit',
settings.value.github.branch,
settings.value.github.dir,
$config.contentDir,
settings.value.github.dir || '',
`${props.page.path}${props.page.extension}`.replace(/^\//g, '')
]
.filter(Boolean)
Expand Down
2 changes: 1 addition & 1 deletion src/defaultTheme/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default <Module>function themeSetupModule() {
subDirs.forEach((path: string) => dirs.push({ path, global: true }))
} else {
// Watch existence of root `components` directory
nuxt.options.watch.push(componentsDirPath)
options.watch.push(componentsDirPath)
}
})

Expand Down
5 changes: 2 additions & 3 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ const config = {
}

export default <Module>function docusI18n() {
const { requireModule, addPlugin, nuxt } = this
const { requireModule, addPlugin, nuxt, $docus } = this
const { options } = nuxt

// Update i18n langDir to relative from `~` (https://github.com/nuxt-community/i18n-module/blob/4bfa890ff15b43bc8c2d06ef9225451da711dde6/src/templates/utils.js#L31)
config.langDir = join(relative(options.srcDir, r('languages')), '/')

if (!options.i18n?.locales?.length) {
const contentDir = resolve(options.srcDir, options.dir.pages)

const contentDir = resolve(options.srcDir, $docus.settings.contentDir)
const languageCodes = languages.map(({ code }) => code)
const activeLanguages = fs.readdirSync(contentDir).filter(name => languageCodes.includes(name))
activeLanguages.unshift(config.defaultLocale)
Expand Down
5 changes: 2 additions & 3 deletions src/settings/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { DocusSettings } from '../types'

export const docusDefaults: DocusSettings = {
title: 'Docus',
contentDir: 'pages',
url: '',
description: '',
template: 'docs',
logo: '',
url: '',
layout: '',
credits: true
}
1 change: 1 addition & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default <Module>function settingsModule() {
console.warn('`themeDir` is not specified in current theme, fallback to default theme')
options.themeDir = resolve(__dirname, '..', 'defaultTheme')
}

let themeDefaultsPath = resolve(options.themeDir, 'settings')
if (existsSync(themeDefaultsPath + '.js')) themeDefaultsPath += '.js'
else if (existsSync(themeDefaultsPath + '.ts')) themeDefaultsPath += '.ts'
Expand Down
3 changes: 1 addition & 2 deletions src/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ export interface DocusDocument {

export interface DocusSettings<T = DefaultThemeSettings> {
title: string
contentDir: string
description: string
credits: boolean
logo: string
url: string
layout: string
template: string
theme?: T
[key: string]: any
Expand Down

1 comment on commit 23571b1

@vercel
Copy link

@vercel vercel bot commented on 23571b1 May 31, 2021

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

Please sign in to comment.