add: article view
View for blog articles, with date filter
This commit is contained in:
parent
4104477533
commit
9abd595b49
3 changed files with 6 additions and 7 deletions
|
@ -27,7 +27,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const { data: article } = await useAsyncData('article', () => queryCollection('blog').path(route.path).first())
|
const { data: article } = await useAsyncData('article', () => queryCollection('blog').path(route.path).where('date', '<', tomorrow(new Date())).first())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
@ -26,13 +26,8 @@ import type { Category } from '../../components/Blog/types'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const simpleDate = (date: Date) => {
|
|
||||||
date.setDate(date.getDate() + 1)
|
|
||||||
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data: articles } = await useAsyncData('articles', () => queryCollection('blog')
|
const { data: articles } = await useAsyncData('articles', () => queryCollection('blog')
|
||||||
.where('date', '<', simpleDate(new Date()))
|
.where('date', '<', tomorrow(new Date()))
|
||||||
.order('date', 'DESC')
|
.order('date', 'DESC')
|
||||||
.all(),
|
.all(),
|
||||||
)
|
)
|
||||||
|
|
4
app/utils/date.ts
Normal file
4
app/utils/date.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export const tomorrow = (date: Date) => {
|
||||||
|
date.setDate(date.getDate() + 1)
|
||||||
|
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue