From fa8ed1c1046ee1e502dc4177458ca762f437f608 Mon Sep 17 00:00:00 2001
From: thomas
Date: Mon, 2 Mar 2020 19:05:30 +0100
Subject: [PATCH] dynamic route generation
---
components/TheFooter.vue | 9 +--
nuxt.config.js | 59 ++++++++++++++++++-
.../_handle/article/_articleHandle/index.vue | 2 +-
pages/index.vue | 11 +---
.../{_handle => privacy-policy}/index.vue | 2 +-
5 files changed, 63 insertions(+), 20 deletions(-)
rename pages/policy/{_handle => privacy-policy}/index.vue (83%)
diff --git a/components/TheFooter.vue b/components/TheFooter.vue
index 4751ef8..271cbbf 100644
--- a/components/TheFooter.vue
+++ b/components/TheFooter.vue
@@ -19,7 +19,7 @@
Policy
@@ -36,12 +36,7 @@
diff --git a/nuxt.config.js b/nuxt.config.js
index 5cb5af1..b34c773 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -1,4 +1,5 @@
require('dotenv').config()
+const axios = require("axios")
export default {
mode: 'universal',
/*
@@ -28,7 +29,7 @@ export default {
*/
plugins: [
{ src: '~/plugins/localStorage.js', ssr: false },
- { src: '~/plugins/moment', ssr: false }
+ { src: '~/plugins/moment' }
],
/*
** Nuxt.js dev-modules
@@ -61,6 +62,62 @@ export default {
domain: process.env.DOMAIN, // your shopify domain
storefrontAccessToken: process.env.STOREFRONT_ACCESS_TOKEN// your shopify storefront access token
},
+ generate: {
+ routes () {
+ return axios({
+ url: process.env.API_URL,
+ method: 'POST',
+ headers: {
+ 'X-Shopify-Storefront-Access-Token': process.env.STOREFRONT_ACCESS_TOKEN,
+ Accept: 'application/json'
+ },
+ data: {
+ query: `query {
+ blogs (first: 250) {
+ edges {
+ node {
+ handle,
+ articles (first: 250) {
+ edges {
+ node {
+ handle
+ }
+ }
+ }
+ }
+ }
+ },
+ products (first: 250) {
+ edges {
+ node {
+ handle
+ }
+ }
+ }
+ }`
+ }
+ }).then((response) => {
+ const blogRoutes = response.data.data.blogs.edges
+ const productRoutes = response.data.data.products.edges
+ const CollectionRoutes = response.data.data.collections.edges
+ // eslint-disable-next-line no-console
+ console.log(blogRoutes)
+ const res = []
+ blogRoutes.forEach((blog) => {
+ blog.node.articles.edges.forEach((article) => {
+ res.push('/blog/' + blog.node.handle + '/article/' + article.node.handle)
+ })
+ })
+ productRoutes.forEach((product) => {
+ res.push('/products/' + product.node.handle)
+ })
+ CollectionRoutes.forEach((collection) => {
+ res.push('/collection/' + collection.node.handle)
+ })
+ return res
+ })
+ }
+ },
/*
** Build configuration
*/
diff --git a/pages/blog/_handle/article/_articleHandle/index.vue b/pages/blog/_handle/article/_articleHandle/index.vue
index 150ca7e..bc98e5d 100644
--- a/pages/blog/_handle/article/_articleHandle/index.vue
+++ b/pages/blog/_handle/article/_articleHandle/index.vue
@@ -19,7 +19,7 @@
{{ article.title }}
@{{ article.authorV2.name }}
- {{ $moment(article.publishedAt).format('DD MMMM Y') }}
+ {{ $moment(article.publishedAt, $moment.ISO_8601).format('DD MMMM Y') }}
diff --git a/pages/index.vue b/pages/index.vue
index 52b8887..052c7c2 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -51,16 +51,7 @@ export default {
query: `query {
shop {
name,
- description,
- privacyPolicy {
- handle
- },
- termsOfService {
- handle
- },
- refundPolicy {
- handle
- }
+ description
},
blogs(first: 10) {
edges {
diff --git a/pages/policy/_handle/index.vue b/pages/policy/privacy-policy/index.vue
similarity index 83%
rename from pages/policy/_handle/index.vue
rename to pages/policy/privacy-policy/index.vue
index fa14522..1e47437 100644
--- a/pages/policy/_handle/index.vue
+++ b/pages/policy/privacy-policy/index.vue
@@ -1,6 +1,6 @@
-
Policy
+ Privacy Policy