Skip to content

Commit

Permalink
paging working now; default to single page of posts; need to add "nex…
Browse files Browse the repository at this point in the history
…t/prev" page links next!
  • Loading branch information
traceypooh committed Jul 10, 2024
1 parent fc0b165 commit 0ed4afc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions js/blogtini.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { markdown_to_html, summarize_markdown } from './text.js'
// eslint-disable-next-line no-console
const log = console.log.bind(console)


// log(new URLSearchParams(location?.search))
const SEARCH = decodeURIComponent(location?.search)
const filter_tag = (SEARCH.match(/^\?tags\/([^&]+)/) || ['', ''])[1]
const filter_cat = (SEARCH.match(/^\?categories\/([^&]+)/) || ['', ''])[1]
const state = {
tags: {},
cats: {},
Expand All @@ -28,12 +31,10 @@ const state = {
pathrel: '',
is_homepage: globalThis.document?.querySelector('body').classList.contains('homepage'),
filter_post_url: null,
page: Number((SEARCH.match(/[?&]page=(\d+)/) || [1, 1])[1]) - 1,
list_tags: !filter_tag && SEARCH.match(/[?&]tags/),
list_cats: !filter_cat && SEARCH.match(/[?&]categories/),
}
const SEARCH = decodeURIComponent(location?.search)
const filter_tag = (SEARCH.match(/^\?tags\/([^&]+)/) || ['', ''])[1]
const filter_cat = (SEARCH.match(/^\?categories\/([^&]+)/) || ['', ''])[1]
state.list_tags = SEARCH.match(/^\?tags[^/]*$/)
state.list_cats = SEARCH.match(/^\?categories[^/]*$/)
const filter_post = (state.is_homepage ? '' :
`${location?.origin}${location?.pathname}`.replace(/\/index\.html$/, '/'))

Expand Down Expand Up @@ -590,6 +591,11 @@ function storage_loop() {
if (!filter_post)
state.urls_filtered.push(post.url)
}

state.urls_filtered = state.urls_filtered.slice(
state.page * cfg.posts_per_page,
state.page * cfg.posts_per_page + cfg.posts_per_page,
)
}


Expand Down

0 comments on commit 0ed4afc

Please sign in to comment.