refactor: improve pagination logic and URL handling

Enhanced pagination logic by adjusting the condition for displaying the 'Before' link, ensuring it appears when there's more than one item, improving user navigation. Improved URL handling in Telegram post and reply processing by using regular expressions for channel replacement, enhancing compatibility and robustness.
This commit is contained in:
ccbikai
2024-08-13 12:03:20 +08:00
parent efb64f3d97
commit 958109752b
2 changed files with 3 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ const afterCursor = posts[0]?.id
<div class="pages-container">
{
before && beforeCursor > 20 ? (
before && beforeCursor > 1 ? (
<a
href={`${SITE_URL}before/${beforeCursor}`}
title="Before"

View File

@@ -93,7 +93,7 @@ function getReply($, item, { channel }) {
const href = reply?.attr('href')
if (href) {
const url = new URL(href)
reply?.attr('href', `${url.pathname}`.replace(channel, 'posts'))
reply?.attr('href', `${url.pathname}`.replace(new RegExp(`/${channel}/`, 'i'), '/posts/'))
}
return $.html(reply)
@@ -130,7 +130,7 @@ function getPost($, item, { channel, staticProxy, index = 0 }) {
? modifyHTMLContent($, $(item).find('.tgme_widget_message_text.js-message_text'), { index })
: modifyHTMLContent($, $(item).find('.tgme_widget_message_text'), { index })
const title = content?.text()?.match(/^.*?(?=[。::]|http\S)/g)?.[0] ?? content?.text() ?? ''
const id = $(item).attr('data-post')?.replace(`${channel}/`, '')
const id = $(item).attr('data-post')?.replace(new RegExp(`${channel}/`, 'i'), '')
const tags = $(content).find('a[href^="?q="]')?.each((_index, a) => {
$(a)?.attr('href', `/search/${encodeURIComponent($(a)?.text())}`)