Skip to content

Commit

Permalink
refactor: separate last publications part into component, and add it …
Browse files Browse the repository at this point in the history
…at the end of a publication
  • Loading branch information
theovidal committed Sep 25, 2024
1 parent 1964ab1 commit 641911e
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 155 deletions.
69 changes: 69 additions & 0 deletions components/BPublicationBanner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<v-row>
<v-col
cols="12"
md="6"
>
<router-link :to="{ name: 'article-id', params: { id: publication.id }}">
<v-img
v-ripple
aspect-ratio="2"
style="border-radius: 20px"
:alt="publication.title"
:src="publication.banner"
/>
</router-link>
</v-col>
<v-col
class="d-flex flex-column justify-center"
cols="12"
md="6"
>
<router-link
:to="{ name: 'article-id', params: { id: publication.id }}"
class="text--text"
>
<slot name="prepend"/>
<h3 class="text-h4 mb-5">
<b-read-indicator :publication="publication.id" />
{{ publication.title }}
</h3>
</router-link>
<p class="lecture-text text--secondary">
{{ publication.description }}
</p>
<v-row class="d-flex justify-space-between ma-0 text--secondary" style="font-size: 12px">
{{ $t('publication.publishedBy', { author: publication.author.displayname, date: timestampToText(publication.timestamp) }) }}
<router-link
v-if="category(publication.category)"
v-ripple
:to="{ name: 'blog', query: { category: category(publication.category).id } }"
class="overline text--text"
style="line-height: 0"
>
<v-icon>{{ category(publication.category).icon }}</v-icon>
{{ $t(`categories.${category(publication.category).id}`) }}
</router-link>
</v-row>
</v-col>
</v-row>
</template>

<script>
import { getCategory } from '~/utils/data'
export default {
name: 'BPublicationBanner',
props: {
publication: {
type: Object,
required: true
}
},
methods: {
category (id) {
return getCategory(id)
}
}
}
</script>
96 changes: 96 additions & 0 deletions components/LastPublications.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<template>
<v-row>
<template v-if="lastPublications.length">
<v-col cols="12">
<b-publication-banner :publication="lastPublications[0]">
<template
v-if="showNew"
#prepend>
<v-btn
class="mb-3"
color="darker"
text>
<v-icon left>
{{ mdiClockOutline }}
</v-icon>
{{ $t('home.new') }}
</v-btn>
</template>
</b-publication-banner>
</v-col>
<v-col
cols="12"
md="10"
offset-md="1"
>
<v-row>
<v-col
v-for="lastPublication in lastPublications.slice(1, 3)"
:key="`publication-${lastPublication.id}`"
cols="12"
md="6"
>
<b-publication-card :publication="lastPublication" />
</v-col>
</v-row>
</v-col>
<v-col
cols="12"
class="text-center">
<v-btn
color="dark"
class="white--text"
to="/blog">
Voir tout
<v-icon right>
{{ mdiChevronRight }}
</v-icon>
</v-btn>
</v-col>
</template>
<v-col
v-else
cols="12">
<v-skeleton-loader
style="width: 100%"
type="image, card-heading, actions"></v-skeleton-loader>
</v-col>
</v-row>
</template>

<script>
import { mdiClockOutline, mdiChevronRight } from '@mdi/js'
export default {
name: 'LastPublications',
props: {
showNew: {
type: Boolean,
default: false
},
exclude: {
type: String,
default: ''
}
},
async fetch () {
// Get 3 last publications, sorted by timestamp
const lastPublications = await this.$content('blog-posts').where({ slug: { $ne: this.exclude } }).without(['body']).sortBy('timestamp', 'desc').limit(3).fetch()
const authorIds = [...new Set(lastPublications.map(v => v.authorId))]
const authors = await this.$content('members').where({ username: { $in: authorIds } }).fetch()
lastPublications.forEach((v) => {
v.id = v.slug
v.author = authors.find(a => a.slug === v.authorId) || {}
})
this.lastPublications = lastPublications
},
data () {
return {
lastPublications: [],
mdiClockOutline,
mdiChevronRight
}
}
}
</script>
4 changes: 4 additions & 0 deletions pages/article/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
</v-col>
</v-row>
</v-col>
<v-col cols="12">
<p class="text-h2 text-center darker--text">Nos dernières publications</p>
<last-publications :exclude="$route.params.id"/>
</v-col>
</v-row>
</v-container>
</template>
Expand Down
55 changes: 2 additions & 53 deletions pages/blog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,53 +41,7 @@
:key="publication.id"
cols="12"
>
<v-row>
<v-col
cols="12"
md="6"
>
<router-link :to="{ name: 'article-id', params: { id: publication.id }}">
<v-img
v-ripple
aspect-ratio="2"
style="border-radius: 20px"
:alt="publication.title"
:src="publication.banner"
/>
</router-link>
</v-col>
<v-col
class="d-flex flex-column justify-center"
cols="12"
md="6"
>
<router-link
:to="{ name: 'article-id', params: { id: publication.id }}"
class="text--text"
>
<h3 class="text-h3 mb-5">
<b-read-indicator :publication="publication.id" />
{{ publication.title }}
</h3>
</router-link>
<p class="lecture-text text--secondary">
{{ publication.description }}
</p>
<v-row class="d-flex justify-space-between ma-0 text--secondary" style="font-size: 12px">
{{ $t('publication.publishedBy', { author: publication.author.displayname, date: timestampToText(publication.timestamp) }) }}
<router-link
v-if="category(publication.category)"
v-ripple
:to="{ name: 'blog', query: { category: category(publication.category).id } }"
class="overline text--text"
style="line-height: 0"
>
<v-icon>{{ category(publication.category).icon }}</v-icon>
{{ $t(`categories.${category(publication.category).id}`) }}
</router-link>
</v-row>
</v-col>
</v-row>
<b-publication-banner :publication="publication" />
</v-col>
<v-col
v-else
Expand Down Expand Up @@ -147,7 +101,7 @@

<script>
import { mdiMagnify, mdiTextBoxMultipleOutline } from '@mdi/js'
import { categories, getCategory, types } from '@/utils/data'
import { categories, types } from '@/utils/data'
export default {
name: 'List',
Expand Down Expand Up @@ -288,11 +242,6 @@ export default {
if (search) {
this.search = search
}
},
methods: {
category (id) {
return getCategory(id)
}
}
}
</script>
106 changes: 4 additions & 102 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,89 +37,9 @@
</v-row>
</v-carousel-item>
</v-carousel>
<v-container v-if="lastPublications" class="page-body">
<v-row>
<v-col
cols="12"
md="10"
offset-md="1"
>
<b-card
v-if="lastPublications.length"
:to="{ name: 'article-id', params: { id: lastPublications[0].id }}"
fluid
>
<v-row class="ma-0">
<v-col
class="d-flex pa-0"
cols="12"
md="6"
>
<v-img
id="first-publication"
aspect-ratio="2"
:src="lastPublications[0].banner"
/>
</v-col>
<v-col
cols="12"
md="6"
>
<v-btn
class="mb-3"
color="darker"
text
>
<v-icon left>
{{ mdiClockOutline }}
</v-icon>
{{ $t('home.new') }}
</v-btn>
<h2 class="text-h4 text--text lecture-title mb-3">
{{ lastPublications[0].title }}
</h2>
<p class="lecture-text text--secondary">
{{ lastPublications[0].description }}
</p>
</v-col>
</v-row>
</b-card>
<v-skeleton-loader
v-else
style="width: 100%"
type="image, card-heading, actions"
/>
</v-col>
<v-col
cols="12"
md="10"
offset-md="1"
>
<v-row>
<v-col
v-for="lastPublication in lastPublications.slice(1, 3)"
:key="`publication-${lastPublication.id}`"
cols="12"
md="6"
>
<b-publication-card :publication="lastPublication" />
</v-col>
</v-row>
</v-col>
<v-col
cols="12"
class="text-center">
<v-btn
color="dark"
class="white--text"
to="/blog">
Voir tout
<v-icon right>
{{ mdiChevronRight }}
</v-icon>
</v-btn>
</v-col>
</v-row>
<v-container class="page-body">
<last-publications
show-new/>
</v-container>
<gradient-rule />
<v-container class="page-body">
Expand Down Expand Up @@ -159,21 +79,9 @@
</template>

<script>
import { mdiClockOutline, mdiChevronRight } from '@mdi/js'
import { categories, types } from '@/utils/data'
export default {
name: 'Home',
async asyncData ({ $content }) {
// Get 3 last publications, sorted by timestamp
const lastPublications = await $content('blog-posts').without(['body']).sortBy('timestamp', 'desc').limit(3).fetch()
const authorIds = [...new Set(lastPublications.map(v => v.authorId))]
const authors = await $content('members').where({ username: { $in: authorIds } }).fetch()
lastPublications.forEach((v) => {
v.id = v.slug
v.author = authors.find(a => a.slug === v.authorId) || {}
})
const carousel = [
{
title: 'BecauseOfProg',
Expand Down Expand Up @@ -204,18 +112,12 @@ export default {
}
return {
lastPublications,
carousel
}
},
data () {
return {
lastPublications: [],
carousel: [],
categories,
types,
mdiClockOutline,
mdiChevronRight
carousel: []
}
},
head () {
Expand Down

0 comments on commit 641911e

Please sign in to comment.