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

move layout concerns out of app.vue #99

Merged
merged 3 commits into from
Aug 25, 2024
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
47 changes: 32 additions & 15 deletions packages/content/layouts/article.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
<script setup>
const sidebar = useSidebar()
</script>

<template lang="pug">
article
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}
Breadcrumbs(v-if="doc.breadcrumbs !== false")
Byline(v-if="doc.authors" :authors="doc.authors")
TagLists(:page="doc" :exclude="['authors']")
Toc(v-if="doc.toc === true")
.hidden-title
slot/
PrevNext(v-if="doc.prevnext !== false")
template(#empty)
slot/
template(#not-found)
slot/
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
article.prose
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}
Breadcrumbs(v-if="doc.breadcrumbs !== false")
Byline(v-if="doc.authors" :authors="doc.authors")
TagLists(:page="doc" :exclude="['authors']")
Toc(v-if="doc.toc === true")
.hidden-title
slot/
PrevNext(v-if="doc.prevnext !== false")
template(#empty)
slot/
template(#not-found)
slot/

AppFooter
</template>
40 changes: 29 additions & 11 deletions packages/content/layouts/form.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
<script setup>
const sidebar = useSidebar()
</script>

<template lang="pug">
div
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
.prose
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}

TntForm.space-y-5(
:action="doc.action"
:method="doc.method"
:fullErrors="doc.fullErrors"
:body="doc.body"
:schema="doc.schema"
)
TntForm.space-y-5(
:action="doc.action"
:method="doc.method"
:fullErrors="doc.fullErrors"
:body="doc.body"
:schema="doc.schema"
)

AppFooter
</template>


<!--
TODO: Support markdown. Maybe by adding a <slot /> to TntForm as alternative to :body
-->
57 changes: 36 additions & 21 deletions packages/content/layouts/list.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
<script setup>
const sidebar = useSidebar()

const route = useRoute()
const { data: page } = await useAsyncData(`tnt-list-${route.path}`, () => queryContent(route.path).findOne())
</script>

<template lang="pug">
article
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}
Breadcrumbs(v-if="doc.breadcrumbs !== false")
TagLists
Toc(v-if="doc.toc === true")
.hidden-title
slot/
ArticleList(:sort="doc.sort")
PrevNext(v-if="doc.prevnext")
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
article.prose
ContentDoc
template(#default="{ doc }")
h1 {{ doc.title }}
Breadcrumbs(v-if="doc.breadcrumbs !== false")
TagLists
Toc(v-if="doc.toc === true")
.hidden-title
slot/
ArticleList(:sort="doc.sort")
PrevNext(v-if="doc.prevnext")

template(#empty)
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
TagLists
ArticleList(:sort="page.sort")
PrevNext(v-if="page.prevnext")

template(#empty)
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
TagLists
ArticleList(:sort="page.sort")
PrevNext(v-if="page.prevnext")
template(#not-found)
h1 {{ _startCase(path.split('/').pop()) }}
Breadcrumbs
ArticleList

template(#not-found)
h1 {{ _startCase(path.split('/').pop()) }}
Breadcrumbs
ArticleList
AppFooter
</template>
33 changes: 25 additions & 8 deletions packages/content/layouts/redirect.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
<script setup>
const sidebar = useSidebar()

const route = useRoute()
const { data: page } = await useAsyncData(`tnt-redirect-${route.path}`, () => queryContent(route.path).findOne())

useHead({
title: `Redirecting to ${page.value.title}...`,
meta: [{ "http-equiv": "refresh", content: `0; URL=${page.value.link}` }],
link: [{ rel: "canonical", href: page.value.link }]
})

navigateTo(page.value.link, {
external: /^https?:\/\//i.test(page.value.link)
})
</script>

<template lang="pug">
div
h1 Redirecting to {{ page.title }}...
p
| If you are not redirected automatically, click here:
|
NuxtLink(:to="page.link") {{ page.link }}
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
.prose
h1 Redirecting to {{ page.title }}...
p
| If you are not redirected automatically, click here:
|
NuxtLink(:to="page.link") {{ page.link }}

AppFooter
</template>
39 changes: 27 additions & 12 deletions packages/content/layouts/tags.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup>
const sidebar = useSidebar()

const { path, params } = useRoute()

// Get taxonomy and tag name from route params
Expand Down Expand Up @@ -26,16 +28,29 @@ if (page && page.title) {
</script>

<template lang="pug">
article
template(v-if="page")
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
ContentRenderer(:value="page")
template(#empty)
// Empty
template(v-else)
h1 {{ _startCase(tag) }}
Breadcrumbs

ArticleList(path="/", :query="{ where: { [taxonomy]: { $or: orConditions } } }")
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
article.prose
template(v-if="page")
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
ContentRenderer(:value="page")
template(#empty)
// Empty
template(v-else)
h1 {{ _startCase(tag) }}
Breadcrumbs

ArticleList(path="/", :query="{ where: { [taxonomy]: { $or: orConditions } } }")

AppFooter
</template>
37 changes: 26 additions & 11 deletions packages/content/layouts/taxonomy.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup>
const sidebar = useSidebar()

const { path, params } = useRoute()

const taxonomy = params.tag[0]
Expand All @@ -11,15 +13,28 @@ const tags = _uniq(contentQuery.map((c) => c[taxonomy]).flat())
</script>

<template lang="pug">
article
template(v-if="page")
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
ContentRenderer(:value="page")
template(#empty)
// Empty
template(v-else)
h1 {{ _startCase(taxonomy) }}
Breadcrumbs
TaxonomyTagList(:taxonomy="taxonomy" :tags="tags")
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
article.prose
template(v-if="page")
h1 {{ page.title }}
Breadcrumbs(v-if="page.breadcrumbs !== false")
ContentRenderer(:value="page")
template(#empty)
// Empty
template(v-else)
h1 {{ _startCase(taxonomy) }}
Breadcrumbs
TaxonomyTagList(:taxonomy="taxonomy" :tags="tags")

AppFooter
</template>
11 changes: 5 additions & 6 deletions packages/content/pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ if (contentHead) {
</script>

<template lang="pug">
.prose
NuxtLayout(:name="page?.layout || layout || 'default'")
ContentRenderer(v-if="page" :key="page._id" :value="page")
template(#empty="{ value }")
DocumentDrivenEmpty(:value="value")/
DocumentDrivenNotFound(v-else)/
NuxtLayout(:name="page?.layout || layout || 'default'")
ContentRenderer(v-if="page" :key="page._id" :value="page")
template(#empty="{ value }")
DocumentDrivenEmpty(:value="value")/
DocumentDrivenNotFound(v-else)/
</template>
5 changes: 2 additions & 3 deletions packages/content/pages/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { layout } = useAppConfig()
</script>

<template lang="pug">
.prose
NuxtLayout(:name="layout || 'default'")
ContentSearch
NuxtLayout(:name="layout || 'default'")
ContentSearch
</template>
5 changes: 2 additions & 3 deletions packages/content/pages/~[...tag].vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ if (taxonomies.includes(taxonomy) && tag) {
</script>

<template lang="pug">
.prose
NuxtLayout(:name="layout || defaultLayout || 'default'")
//- Rendering handled by layout.
NuxtLayout(:name="layout || defaultLayout || 'default'")
//- Rendering handled by layout.
</template>
19 changes: 2 additions & 17 deletions packages/core/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const bodyClass = computed(() => {
return klasses.join(' ')
})

const sidebar = useSidebar()

useHead({
titleTemplate: (titleChunk) => {
return titleChunk ? `${titleChunk} - ${name}` : name
Expand All @@ -26,21 +24,8 @@ useHead({
</script>

<template lang="pug">
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.flex.flex-col
AppHeader

.flex-1.overflow-y-auto
main
.tnt-container
NuxtPage(:page-key="route => route.fullPath")

AppFooter
div
NuxtPage(:page-key="route => route.fullPath")

ToastStack
</template>
21 changes: 19 additions & 2 deletions packages/core/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<script setup>
const sidebar = useSidebar()
</script>

<template lang="pug">
div
slot
.flex.h-screen.overflow-hidden
AppSidebar(
class="w-80 transition-all duration-300"
:class="sidebar ? 'ml-0' : '-ml-80'"
)

.flex-1.overflow-y-auto
AppHeader

main
.tnt-container
.prose
slot

AppFooter
</template>
Loading