Table of Contents

Test 1 - Show all

//source https://gridsome.org/docs/taxonomies
api.loadSource(store => {
const posts = store.addContentType('Post')
const tags = store.addContentType('Tag')
// makes all ids in the `tags` field reference a `Tag`
posts.addReference('tags', 'Tag')
tags.addNode({
id: '1',
title: 'The author'
})
posts.addNode({
id: '1',
title: 'A post',
tags: ['1']
})
}
view raw file1.js hosted with ❤ by GitHub
//source: https://gridsome.org/docs/taxonomies
query Tag($id: String!, $page: Int) {
tag(id: $id) {
title
belongsTo(page: $page) @paginate {
totalCount
pageInfo {
totalPages
currentPage
}
edges {
node {
... on Post {
id
title
path
}
}
}
}
}
}
view raw file2.js hosted with ❤ by GitHub
//source: https://gridsome.org/docs/taxonomies
<template>
<Layout>
<h1>{{ $page.tag.title }}</h1>
<ul>
<li v-for="edge in $page.tag.belongsTo.edges" :key="edge.node.id">
<g-link :to="edge.node.path">
{{ edge.node.title }}
</g-link>
</li>
</ul>
</Layout>
</template>
<page-query>
query Tag($id: String!) {
tag(id: $id) {
title
belongsTo {
edges {
node {
... on Post {
id
title
path
}
}
}
}
}
}
</page-query>
view raw file3.js hosted with ❤ by GitHub

Test 2 - Only file1.js with

//source https://gridsome.org/docs/taxonomies
api.loadSource(store => {
const posts = store.addContentType('Post')
const tags = store.addContentType('Tag')
// makes all ids in the `tags` field reference a `Tag`
posts.addReference('tags', 'Tag')
tags.addNode({
id: '1',
title: 'The author'
})
posts.addNode({
id: '1',
title: 'A post',
tags: ['1']
})
}
view raw file1.js hosted with ❤ by GitHub

Test 3 Only file2.js with ?file

//source: https://gridsome.org/docs/taxonomies
query Tag($id: String!, $page: Int) {
tag(id: $id) {
title
belongsTo(page: $page) @paginate {
totalCount
pageInfo {
totalPages
currentPage
}
edges {
node {
... on Post {
id
title
path
}
}
}
}
}
}
view raw file2.js hosted with ❤ by GitHub

Test 4 Only file1.js with Line Highlighting for Line 1,3,5-10, 15-20

//source https://gridsome.org/docs/taxonomies
api.loadSource(store => {
const posts = store.addContentType('Post')
const tags = store.addContentType('Tag')
// makes all ids in the `tags` field reference a `Tag`
posts.addReference('tags', 'Tag')
tags.addNode({
id: '1',
title: 'The author'
})
posts.addNode({
id: '1',
title: 'A post',
tags: ['1']
})
}
view raw file1.js hosted with ❤ by GitHub