-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate last publications part into component, and add it …
…at the end of a publication
- Loading branch information
Showing
5 changed files
with
175 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters