Skip to content

Commit

Permalink
Merge pull request #6 from neilherbertuk/main
Browse files Browse the repository at this point in the history
Changable Sidebar Component
  • Loading branch information
xqsit94 authored Feb 25, 2022
2 parents 8de16b1 + e1b2961 commit 2421a08
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 11 deletions.
1 change: 1 addition & 0 deletions blog/2021-10-18-archived.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags: ['archived']
categories: ['archived']
thumbnail: ./archived.png
is_archived: true
sidebar: Alternative
---

## How to Archive Post
Expand Down
15 changes: 15 additions & 0 deletions gridsome.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,19 @@ module.exports = function (api) {
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api/
})

api.loadSource(({ addSchemaResolvers }) => {
// Schema API here: https://gridsome.org/docs/schema-api/
// Create a default value for "sidebar" to prevent Cannot query errors if not used
addSchemaResolvers({
Post: {
sidebar: {
type: 'String',
resolve(obj) {
return (obj.sidebar === undefined ? 'Default' : obj.sidebar)
}
}
}
})
})
}
25 changes: 17 additions & 8 deletions src/components/parts/AppSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<template>
<div class="w-full flex flex-col my-4">
<p class="text-xl font-semibold pb-5">Sidebar</p>
<p class="pb-2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas mattis
est eu odio sagittis tristique. Vestibulum ut finibus leo. In hac
habitasse platea dictumst.
</p>
</div>
<component :is="component" />
</template>

<script>
export default {
name: 'sidebar',
props: {
sidebar: {
default: 'Default'
}
},
computed: {
component() {
return () => import(`~/components/sidebars/${this.sidebar}`)
}
}
}
</script>
10 changes: 10 additions & 0 deletions src/components/sidebars/Alternative.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div class="w-full flex flex-col my-4">
<p class="text-xl font-semibold pb-5">Alt Sidebar</p>
<p class="pb-2">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</template>
29 changes: 29 additions & 0 deletions src/components/sidebars/Categories.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div className="w-full flex flex-col my-4">
<h2 class="title-font text-lg font-medium mb-3">CATEGORIES</h2>
<nav class="list-none mb-5">
<ul v-for="category in $static.category.edges">
<li>
<g-link :to="category.node.path">{{ category.node.title | capitalise }} ({{ category.node.belongsTo.totalCount }})</g-link>
</li>
</ul>
</nav>
</div>
</template>

<static-query>
query {
category: allCategory(sortBy: "title", order: ASC) {
edges {
node {
id
title
path
belongsTo {
totalCount
}
}
}
}
}
</static-query>
10 changes: 10 additions & 0 deletions src/components/sidebars/Default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div class="w-full flex flex-col my-4">
<p class="text-xl font-semibold pb-5">Sidebar</p>
<p class="pb-2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas mattis
est eu odio sagittis tristique. Vestibulum ut finibus leo. In hac
habitasse platea dictumst.
</p>
</div>
</template>
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ export default function (Vue, { router, head, isClient }) {
perPage: process.env.VSSUE_GRIDSOME_PERPAGE || 15,
autoCreateIssue: process.env.GRIDSOME_VSSUE_OWNER || false,
})

// Add vue filter to capitalise the first letter of each word
Vue.filter('capitalise', function (value) {
let output = []
value.split(' ').forEach(word => {
output.push(
word.charAt(0).toUpperCase() +
word.slice(1).toLowerCase()
)
})
return output.join(' ')
}
)
}
2 changes: 1 addition & 1 deletion src/pages/Blog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
dark:border-gray-700
"
>
<app-sidebar />
<app-sidebar sidebar="Categories" />
</aside>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/Category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
dark:border-gray-700
"
>
<app-sidebar />
<app-sidebar sidebar="Categories" />
</aside>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/templates/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"
aria-label="right-sidebar"
>
<app-sidebar />
<app-sidebar :sidebar="$page.post.sidebar" />
</aside>
</div>
</Layout>
Expand All @@ -146,6 +146,7 @@ query Post ($path: String!) {
title
summary
is_archived
sidebar
thumbnail
path
date (format: "MMMM D, Y")
Expand Down

0 comments on commit 2421a08

Please sign in to comment.