diff --git a/components/cards/BlogPostCard.vue b/components/cards/BlogPostCard.vue index 182bcd4..608d973 100644 --- a/components/cards/BlogPostCard.vue +++ b/components/cards/BlogPostCard.vue @@ -1,12 +1,12 @@ diff --git a/package-lock.json b/package-lock.json index 527a2eb..76926c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "themeparks-nuxtjs", - "version": "1.5.8", + "version": "1.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "themeparks-nuxtjs", - "version": "1.5.8", + "version": "1.6.0", "license": "MIT", "dependencies": { "@kangc/v-md-editor": "^1.7.12", diff --git a/package.json b/package.json index e9eb1ee..13711a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "themeparks-nuxtjs", - "version": "1.5.9", + "version": "1.6.0", "private": false, "repository": { "url": "https://github.com/timyboy12345/Themeparks-NuxtJS" diff --git a/pages/blog/:slug/edit.vue b/pages/blog/:slug/edit.vue deleted file mode 100644 index eea3608..0000000 --- a/pages/blog/:slug/edit.vue +++ /dev/null @@ -1,157 +0,0 @@ - - - diff --git a/pages/blog/:slug/index.vue b/pages/blog/:slug/index.vue index 19134e6..2564e49 100644 --- a/pages/blog/:slug/index.vue +++ b/pages/blog/:slug/index.vue @@ -12,23 +12,25 @@
Foto van blogpost
-

{{ blogPost.title }}

+

{{ blogPost.translations[0].title }}

- {{ blogPost.createdAt | formatDate }} - - - | {{ blogPost.author.firstName }} + {{ (blogPost.translations[0].date_updated || blogPost.translations[0].date_created) | formatDate }} + | {{ blogPost.user_created.first_name }}

-
+
- @@ -61,7 +64,7 @@ d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125" /> - +
@@ -98,21 +101,7 @@ export default { } }, async fetch() { - await this.$axios - .get('/blog-posts/slug/' + this.$route.params.slug) - .then(async (blogPost) => { - this.blogPost = blogPost.data - - if (blogPost.data.parkId) { - await this.loadPark(blogPost.data.parkId) - await this.loadParkBlogPosts(blogPost.data.parkId) - } - }) - .catch((reason) => { - this.$emit('fetchError', reason) - this.$sentry.captureException(reason) - throw reason - }) + await this.fetchBlogPost() }, head() { return { @@ -146,14 +135,14 @@ export default { }, ] - if (this.blogPost.parkId) { + if (this.blogPost.park_id) { if (this.park) { bc = bc.concat({ title: this.park.name, url: '/blog?park=' + this.park.id }) } } return bc.concat({ - title: this.blogPost.title, + title: this.blogPost.translations[0].title, url: '#', }) }, @@ -173,8 +162,8 @@ export default { }, async loadParkBlogPosts(parkId) { this.associatedBlogPosts = await this.$axios - .get('/blog-posts/parks/' + parkId) - .then(({ data: blogPosts }) => { + .get(`https://data.arendz.nl/items/tp_blogpost?filter[park_id][_eq]=${parkId}&fields=*,translations.*,header.*`) + .then(({ data: { data: blogPosts } }) => { return blogPosts.filter((p) => p.id !== this.blogPost.id).slice(0, 5) }) .catch((reason) => { @@ -183,6 +172,31 @@ export default { throw reason }) }, + async fetchBlogPost() { + await this.$axios + .get( + `https://data.arendz.nl/items/tp_blogpost?filter[translations][slug][_eq]=${this.$route.params.slug}&fields=*,translations.*,header.*,user_created.*` + ) + .then(async (blogPosts) => { + const isoLocale = this.$i18n.locales.find((l) => l.code === this.$i18n.getLocaleCookie()).iso + + if (blogPosts.data.data[0].translations[0].languages_code !== isoLocale) { + throw new Error('Not the right locale') + } + + this.blogPost = blogPosts.data.data[0] + + if (blogPosts.data.data[0].park_id) { + await this.loadPark(blogPosts.data.data[0].park_id) + await this.loadParkBlogPosts(blogPosts.data.data[0].park_id) + } + }) + .catch((reason) => { + this.$emit('fetchError', reason) + this.$sentry.captureException(reason) + throw reason + }) + }, }, } diff --git a/pages/blog/create.vue b/pages/blog/create.vue deleted file mode 100644 index ddbc82a..0000000 --- a/pages/blog/create.vue +++ /dev/null @@ -1,139 +0,0 @@ - - - diff --git a/pages/blog/index.vue b/pages/blog/index.vue index 1b36060..70d1180 100644 --- a/pages/blog/index.vue +++ b/pages/blog/index.vue @@ -21,15 +21,16 @@
- - +
@@ -52,14 +53,23 @@ export default { } }, async fetch() { + const isoLocale = this.$i18n.locales.find((l) => l.code === this.$i18n.getLocaleCookie()).iso + + // Fetch all blog posts with the right locale await this.$axios - .get('/blog-posts') + .get( + `https://data.arendz.nl/items/tp_blogpost?filter[translations][languages_code][_eq]=${isoLocale}&fields=*,translations.*,header.*` + ) .then((blogPosts) => { - this.blogPosts = blogPosts.data + this.blogPosts = blogPosts.data.data }) .catch((reason) => { + this.$emit('fetchError', reason) + this.$sentry.captureException(reason) throw reason }) + + // Fetch a list of all parks for the filters await this.$axios .get('/parks') .then((parks) => { @@ -102,11 +112,11 @@ export default { let posts = this.blogPosts if (this.searchQuery) { - posts = posts.filter((p) => p.title.toLowerCase().includes(this.searchQuery.toLowerCase())) + posts = posts.filter((p) => p.translations[0].title.toLowerCase().includes(this.searchQuery.toLowerCase())) } if (this.parkQuery) { - posts = posts.filter((p) => p.parkId === this.parkQuery) + posts = posts.filter((p) => p.park_id === this.parkQuery) } return posts diff --git a/pages/index.vue b/pages/index.vue index bf870f1..8ebd321 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -48,10 +48,14 @@ export default { } }, async fetch() { + const isoLocale = this.$i18n.locales.find((l) => l.code === this.$i18n.getLocaleCookie()).iso + await this.$axios - .get('/blog-posts') - .then(({ data: blogPosts }) => { - this.blogPosts = blogPosts.slice(0, 4) + .get( + `https://data.arendz.nl/items/tp_blogpost?filter[translations][languages_code][_eq]=${isoLocale}&fields=*,translations.*,header.*,user` + ) + .then((blogPosts) => { + this.blogPosts = blogPosts.data.data }) .catch((reason) => { throw reason diff --git a/pages/parks/:id/index.vue b/pages/parks/:id/index.vue index 3072403..fc28c5d 100644 --- a/pages/parks/:id/index.vue +++ b/pages/parks/:id/index.vue @@ -250,15 +250,19 @@ export default { }, }, async created() { - this.blogPosts = await this.$axios - .get('/blog-posts/parks/' + this.parkId) - .then((park) => { - return park.data + const isoLocale = this.$i18n.locales.find((l) => l.code === this.$i18n.getLocaleCookie()).iso + + await this.$axios + .get( + `https://data.arendz.nl/items/tp_blogpost?filter[translations][languages_code][_eq]=${isoLocale}&fields=*,translations.*,header.*,user_created.*` + ) + .then((blogPosts) => { + this.blogPosts = blogPosts.data.data }) - .catch((e) => { - if (e) { - this.$sentry.captureException(e) - } + .catch((reason) => { + this.$emit('fetchError', reason) + this.$sentry.captureException(reason) + throw reason }) }, } diff --git a/plugins/axios.js b/plugins/axios.js index 458483a..f339417 100644 --- a/plugins/axios.js +++ b/plugins/axios.js @@ -1,6 +1,6 @@ export default function ({ app, $axios }) { $axios.onRequest((request) => { - if (request.baseURL.includes('tp.arendz.nl')) { + if (!request.url.includes('data.arendz.nl')) { const locales = app.store.$i18n.locales const localeCookie = app.store.$i18n.getLocaleCookie() @@ -15,7 +15,7 @@ export default function ({ app, $axios }) { } } - // Auth token + // Auth token, only if request is to tp.arendz.nl if (process.client && localStorage.getItem('jwt_token')) { request.headers = { ...request.headers, diff --git a/views/BlogPostList.vue b/views/BlogPostList.vue index f9b986d..611273c 100644 --- a/views/BlogPostList.vue +++ b/views/BlogPostList.vue @@ -8,25 +8,26 @@
-
{{ post.title }}
+
{{ post.translations[0].title }}
- {{ post.createdAt | formatDate }} | {{ post.author.firstName }} + {{ (post.translations[0].date_updated || post.translations[0].date_created) | formatDate }} + | {{ post.user_created.first_name }}