From 47676c56f6cc41673de3bdce6bd897d2722e0c06 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Mon, 22 Feb 2021 18:36:07 +0330 Subject: [PATCH 1/3] feat: draft --- theme/components/templates/AppSearch.vue | 2 +- theme/module.js | 3 ++- theme/pages/_.vue | 4 ++-- theme/plugins/docus.js | 7 ++++++- theme/utils/document.js | 4 ++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/theme/components/templates/AppSearch.vue b/theme/components/templates/AppSearch.vue index 835e3f029..23058004e 100644 --- a/theme/components/templates/AppSearch.vue +++ b/theme/components/templates/AppSearch.vue @@ -76,7 +76,7 @@ export default { return } this.searching = true - this.results = await this.$content(this.$i18n.locale, { deep: true }).sortBy('position', 'asc').only(['title', 'slug', 'category', 'to']).limit(12).search(q).fetch() + this.results = await this.$content({ deep: true }).where({ language: this.$i18n.locale, draft: false }).sortBy('position', 'asc').only(['title', 'slug', 'category', 'to']).limit(12).search(q).fetch() this.searching = false } }, diff --git a/theme/module.js b/theme/module.js index caae30756..4673bec33 100644 --- a/theme/module.js +++ b/theme/module.js @@ -3,7 +3,7 @@ import defu from 'defu' import gracefulFs from 'graceful-fs' import tailwindConfig from './tailwind.config' -import { generatePosition, generateSlug } from './utils/document' +import { generatePosition, generateSlug, isDraft } from './utils/document' const fs = gracefulFs.promises const r = (...args) => resolve(__dirname, ...args) @@ -84,6 +84,7 @@ export default function docusModule () { document.to = generateSlug(_to) document.language = _language document.category = _category + document.draft = document.draft || isDraft(slug) }) // Extend `/` route hook('build:extendRoutes', (routes) => { diff --git a/theme/pages/_.vue b/theme/pages/_.vue index 1c88f7608..c9d2ccd05 100644 --- a/theme/pages/_.vue +++ b/theme/pages/_.vue @@ -41,13 +41,13 @@ export default { async asyncData ({ $content, store, app, params, error }) { const language = app.i18n.locale const to = `/${params.pathMatch || ''}` - const [document] = await $content({ deep: true }).where({ language, to }).fetch() + const [document] = await $content({ deep: true }).where({ language, to, draft: false }).fetch() if (!document) { return error({ statusCode: 404, message: 'Page not found' }) } const [prev, next] = await $content({ deep: true }) - .where({ language }) + .where({ language, draft: false }) .only(['title', 'slug', 'to']) .sortBy('position', 'asc') .surround(document.slug, { before: 1, after: 1 }) diff --git a/theme/plugins/docus.js b/theme/plugins/docus.js index ab2471118..08439a94a 100644 --- a/theme/plugins/docus.js +++ b/theme/plugins/docus.js @@ -116,7 +116,12 @@ export default async function ({ app, $content, $config, nuxtState = {}, beforeN if (process.dev === false && this.categories[app.i18n.locale]) { return } - const docs = await $content({ deep: true }).where({ language: app.i18n.locale }).only(['title', 'menuTitle', 'category', 'slug', 'version', 'to']).sortBy('position', 'asc').fetch() + const docs = await $content({ deep: true }) + .where({ language: app.i18n.locale, draft: false }) + .only(['title', 'menuTitle', 'category', 'slug', 'version', 'to']) + .sortBy('position', 'asc') + .fetch() + if (this.lastRelease) { docs.push({ slug: 'releases', title: 'Releases', category: 'Community', to: '/releases' }) } diff --git a/theme/utils/document.js b/theme/utils/document.js index 8f65a4235..323632b65 100644 --- a/theme/utils/document.js +++ b/theme/utils/document.js @@ -16,6 +16,10 @@ export function generateSlug (path) { .join('/') } +export function isDraft (path) { + return !!path.match(/(\.draft)$/, '$2') +} + function paddLeft (value, length) { return ('0'.repeat(length) + value).substr(String(value).length) } From 1a6bf4c5b29d8db938b56583f288ee031da9b781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 23 Feb 2021 13:58:34 +0100 Subject: [PATCH 2/3] fix: draft dx improvements --- theme/components/dev-templates/DocusUI.vue | 24 +++++++++++-- theme/components/templates/Aside.vue | 6 +++- theme/components/templates/Search.vue | 17 ++++----- theme/components/templates/Toc.vue | 42 +++++++++++----------- theme/pages/_.vue | 11 +++--- theme/plugins/docus.js | 9 +++-- theme/plugins/docus.ui.js | 15 ++++++-- theme/utils/document.js | 2 +- 8 files changed, 82 insertions(+), 44 deletions(-) diff --git a/theme/components/dev-templates/DocusUI.vue b/theme/components/dev-templates/DocusUI.vue index 702f109cf..4fac240bb 100644 --- a/theme/components/dev-templates/DocusUI.vue +++ b/theme/components/dev-templates/DocusUI.vue @@ -1,7 +1,19 @@