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: app container split #338

Merged
merged 25 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
39cc5dc
:fire: (api) remove commented func
Tahul May 26, 2021
b742089
:sparkles: (docus) add currentPage to runtime state
Tahul May 26, 2021
facd94c
:sparkles: (docus) set current page once fetched
Tahul May 26, 2021
dc0ea85
:sparkles: (docus) add layout
Tahul May 26, 2021
2c2023e
:sparkles: (theme) set default theme
Tahul May 26, 2021
b815467
:sparkles: (docus) noop component for template and appcontainer
Tahul May 26, 2021
b987ee9
:sparkles: (docus) set layout
Tahul May 26, 2021
acc69ec
:fire: (theme) update AppPage
Tahul May 26, 2021
0018bf7
:sparkles: (docus) create AppTemplate
Tahul May 26, 2021
78e5f3a
:sparkles: (theme) update templates (wip)
Tahul May 26, 2021
6e2f73c
:fire: (templates) prune old templates
Tahul Jun 1, 2021
f8c9382
:sparkles: (templates) update content templates
Tahul Jun 1, 2021
b34c191
:sparkles: (app) handle template options from page
Tahul Jun 1, 2021
25b95ce
:sparkles: (core) init layout from settings
Tahul Jun 1, 2021
e694a62
:sparkles: (aside) add asideClass to AppAside
Tahul Jun 1, 2021
357a3d9
:sparkles: (layout) update applayout
Tahul Jun 1, 2021
3b3209e
:sparkles: (templates) update actual templates
Tahul Jun 1, 2021
90d6272
:sparkles: (css) move aside transition to main.css
Tahul Jun 1, 2021
ca31642
:label: (types) update types & defaults w/ layout
Tahul Jun 1, 2021
404969a
:bug: (build) return templateOptions as data and set it beforeMount
Tahul Jun 1, 2021
6342c9c
:fire: (components) remove unnecessary src/app components
Tahul Jun 1, 2021
e596edf
:sparkles: (layout) lighten layout key
Tahul Jun 1, 2021
49fe422
:bug: (merge) fix blog layouts after merge
Tahul Jun 2, 2021
962b6f2
:bug: (releases) fix releases after merge
Tahul Jun 2, 2021
e2987b0
feat: Enrich document `layout` based on parents data
farnabaz Jun 2, 2021
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
5 changes: 4 additions & 1 deletion docs/content/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
template: landing
title: Documentation Generator based on Nuxt and Windi.
description: >-
Write pages in markdown, use Vue components, add style with Windi CSS and enjoy the power of Nuxt with a blazing fast developer experience.
template: page
navigation: false
layout:
asideClass: 'block lg:hidden'
aside: true
---

::block-hero
Expand Down
3 changes: 1 addition & 2 deletions docs/content/releases.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
template: releases
menu: false
---

# Releases
# Releases
7 changes: 6 additions & 1 deletion docs/content/templates/pre-launch.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
template: pre-launch
template: page
title: Pre-launch template
layout:
footer: false
aside: true
asideClass: 'bloc lg:hidden'
fluid: true
---


Expand Down
5 changes: 5 additions & 0 deletions src/app/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<AppLayout>
<Nuxt />
</AppLayout>
</template>
6 changes: 4 additions & 2 deletions src/app/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ const r = (...args: any[]) => resolve(__dirname, ...args)

export default <Module>function docusAppModule() {
const { nuxt } = this

nuxt.options.layouts.default = r('layouts/default.vue')

// Extend `/` route
nuxt.hook('build:extendRoutes', (routes: any[]) => {
const hasRoute = (name: string) => routes.some(route => route.name === name)

if (!hasRoute('all')) {
if (!hasRoute('all'))
routes.push({
path: '/*',
name: 'all',
component: r('pages/_.vue')
})
}
})
}
73 changes: 49 additions & 24 deletions src/app/pages/_.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,76 @@
<script>
import Vue from 'vue'
import { withoutTrailingSlash } from 'ufo'
import { defineComponent } from '@nuxtjs/composition-api'

export default {
export default defineComponent({
name: 'PageSlug',

middleware({ app, params, redirect }) {
if (params.pathMatch === 'index') {
redirect(app.localePath('/'))
}
if (params.pathMatch === 'index') redirect(app.localePath('/'))
},
async asyncData({ $docus, app, params, error }) {
const language = app.i18n.locale

async asyncData({ $docus, app: { i18n }, params, error }) {
const language = i18n.locale

// Init template options from Docus settings
let templateOptions = {
...$docus.settings.value.layout
}

// Get the proper current path
const to = withoutTrailingSlash(`/${params.pathMatch || ''}`) || '/'

// TODO: Fix the draft system
const draft = false

// Page query
const [page] = await $docus.search({ deep: true }).where({ language, to, draft }).fetch()
if (!page) {
return error({ statusCode: 404, message: 'Page not found' })
}

// Break on missing page query
if (!page) return error({ statusCode: 404, message: 'Page not found' })

// Get page template
page.template = $docus.getPageTemplate(page)

// Preload the component on client-side navigation
await Vue.component(page.template)()
const component = await Vue.component(page.template)()

return { page }
},
data() {
return {
page: {}
}
// Set layout defaults for this template
if (component.templateOptions) templateOptions = { ...templateOptions, ...component.templateOptions }

// Set layout from page
if (page.layout) templateOptions = { ...templateOptions, ...page.layout }

// Set Docus runtime current page
$docus.currentPage.value = page

return { page, templateOptions }
},

head() {
const head = {
title: this.page.title,
meta: [],
...(this.page.head || {})
}

this.mergeMeta(head.meta, this.pageMeta)

return head
},

computed: {
pageMeta() {
return [
// Open Graph
// OpenGraph
{ hid: 'og:title', property: 'og:title', content: this.page.title },
// Twitter Card
{ hid: 'twitter:title', name: 'twitter:title', content: this.page.title },
/// Page description
...(this.page.description
? [
// Meta description
{
hid: 'description',
name: 'description',
Expand All @@ -71,16 +95,17 @@ export default {
]
: [])
]
},
settings() {
return this.$docus.settings
}
},

beforeMount() {
this.$docus.layout.value = this.templateOptions
},

mounted() {
if (this.page.version) {
localStorage.setItem(`page-${this.page.slug}-version`, this.page.version)
}
if (this.page?.version) localStorage.setItem(`page-${this.page.slug}-version`, this.page.version)
},

methods: {
mergeMeta(to, from) {
from.forEach(newMeta => {
Expand All @@ -92,5 +117,5 @@ export default {
})
}
}
}
})
</script>
3 changes: 2 additions & 1 deletion src/core/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const useDB = () => {
const existed = _items.findOne({ key: document.key })

if (existed) {
return _items.update({ $loki: existed.$loki, meta: existed.meta, ...document })
_items.update({ $loki: existed.$loki, meta: existed.meta, ...document })
return document
}

return _items.insert(document)
Expand Down
2 changes: 1 addition & 1 deletion src/core/parser/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function parse(file, options) {
...data,
toc,
body,
text: content,
text: file,
excerpt
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/core/runtime/composables/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export const useDocusApi = createQuery => {
return links.find(link => link.to === to)
}

// function findLinkBySlug(links: NavItem[], slug: string) {
// return links.find(link => link.slug === slug)
// }

return {
data,
search,
Expand Down
8 changes: 6 additions & 2 deletions src/core/runtime/docus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ export const createDocus = async (

// State
const state = reactive({
currentPage: null,
settings: null,
theme: null
theme: null,
layout: {
...settings.layout
}
}) as DocusState

// Split theme & user settings
Expand Down Expand Up @@ -63,7 +67,7 @@ export const createDocus = async (
await setupAddons()

// Init Docus for every context
await docusInit(docusAddonContext)
docusInit(docusAddonContext)

// Workaround for async data
clientAsyncData(context.app, $nuxt)
Expand Down
Loading