Skip to content

Commit

Permalink
fix: path with extra hash at the end when reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Aug 9, 2023
1 parent ff08ab6 commit 440b2a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/utils/comments/twikoo-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RecentComment, formatTime } from '..'
import { RecentComment, cleanPath, formatTime } from '..'
import { getGravatar, getGravatarUrl } from './gravatar'

declare const twikoo: any
Expand Down Expand Up @@ -51,9 +51,10 @@ export const twikooCommentsCount = async (
envId: string,
path: string
): Promise<number> => {
const cleanedPath = cleanPath(path)
const commentCounts = await twikoo.getCommentsCount({
envId,
urls: [path],
urls: [cleanedPath],
includeReply: true
})
return commentCounts[0] ? Number(commentCounts[0].count) : 0
Expand Down
4 changes: 3 additions & 1 deletion src/utils/comments/valine-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cleanPath } from '..'

declare const Valine: any

interface ValineConfig {
Expand Down Expand Up @@ -36,6 +38,6 @@ export const valineInit = ({
meta: meta ?? [],
requiredFields: requiredFields ?? [],
avatarForce,
path
path: cleanPath(path)
})
}
6 changes: 3 additions & 3 deletions src/utils/comments/waline-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RecentComments
// @ts-expect-error
} from 'https://unpkg.com/@waline/client@v2/dist/waline.mjs'
import { filterHTMLContent, formatTime } from '..'
import { cleanPath, filterHTMLContent, formatTime } from '..'
import { PluginsData } from '@/models/ThemeConfig.class'

type WalinePlugin = PluginsData['waline']
Expand Down Expand Up @@ -78,14 +78,14 @@ export const walineInit = ({
export const walinePageViewInit = (serverURL: string, path: string) => {
pageviewCount({
serverURL,
path
path: cleanPath(path)
})
}

export const walineCommentViewInit = (serverURL: string, path: string) => {
commentCount({
serverURL,
path
path: cleanPath(path)
})
}

Expand Down
8 changes: 8 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ export function convertToLocale(label: string) {

return label
}

export function cleanPath(path: string) {
if (path.at(-1) === '/') {
return path.slice(0, -1)
}

return path
}

0 comments on commit 440b2a7

Please sign in to comment.