Skip to content

Commit

Permalink
fix: πŸ› Broke page listing per month, year fix
Browse files Browse the repository at this point in the history
  • Loading branch information
renoirb committed Oct 30, 2024
1 parent 7e4a858 commit 66d74bb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
14 changes: 9 additions & 5 deletions lib/model/content/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export const isNuxtContentResult = (

export const queryNuxtContent = async (
$content: Context['$content'],
route: Context['route'],
year?: string,
month?: string,
): Promise<INuxtContentResult[]> => {
let contents: INuxtContentResult[] = []
let db: INuxtContentInstance
/**
* Bookmarks:
* - https://github.com/techfort/LokiJS/wiki/Query-Examples#find-queries
Expand All @@ -152,7 +152,14 @@ export const queryNuxtContent = async (
* - http://localhost:3000/_content/blog?deep=true
* - http://localhost:3000/_content/blog?deep=true&created_defined=asdf
*/
const db = $content('blog', { deep: true })
if (year && month) {
db = $content('blog', year, month, { deep: true })
} else if (year) {
db = $content('blog', year, { deep: true })
} else {
db = $content('blog', { deep: true })
}
db = db
.sortBy('createdAt', 'desc')
.only([
'createdAt',
Expand All @@ -168,9 +175,6 @@ export const queryNuxtContent = async (
])

contents = await db.fetch()
contents = contents.filter((a) =>
findExcludingRedirectPredicate(a as INuxtContentResult),
)

return contents
}
Expand Down
1 change: 0 additions & 1 deletion pages/blog/_year/_month/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
class="my-10"
:prev="prev"
:next="next"
style="display: none"
/>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions pages/blog/_year/_month/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
components: {
'blog-list-model-by-year': BlogListModelByYear,
},
async asyncData({ $content, route, params }) {
async asyncData({ $content, params }) {
let contents: INuxtContentIndexResult[] = []
try {
contents = await queryNuxtContent(
$content,
route,
params.year,
params.month,
)
Expand Down
4 changes: 2 additions & 2 deletions pages/blog/_year/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
components: {
'blog-list-model-by-year': BlogListModelByYear,
},
async asyncData({ $content, route, params }) {
async asyncData({ $content, params }) {
let contents: INuxtContentIndexResult[] = []
try {
contents = await queryNuxtContent($content, route, params.year)
contents = await queryNuxtContent($content, params.year)
} catch (_) {
// ..
}
Expand Down
4 changes: 2 additions & 2 deletions pages/blog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
components: {
'blog-list-model-by-year': BlogListModelByYear,
},
async asyncData({ $content, route }) {
async asyncData({ $content }) {
let contents: INuxtContentIndexResult[] = []
contents = await queryNuxtContent($content, route)
contents = await queryNuxtContent($content)
return {
contents,
pageTitle: 'Blog',
Expand Down

0 comments on commit 66d74bb

Please sign in to comment.