Skip to content

Commit 4dd4040

Browse files
committed
+ env NUXT_PUBLIC_TIEBA_IMAGE_PROXY to allow custom the interpolation for url of tieba images with its urlFilename @ utils/post/renderer/content.ts
@ fe
1 parent cd47892 commit 4dd4040

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

fe/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ NUXT_SITE_URL= # https://github.com/harlan-zw/nuxt-site-config/issues/32
33
NUXT_PUBLIC_BE_URL=
44
NUXT_PUBLIC_INSTANCE_NAME=
55
NUXT_PUBLIC_FOOTER_TEXT=
6+
NUXT_PUBLIC_TIEBA_IMAGE_PROXY=

fe/nuxt.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export default defineNuxtConfig({
6767
public: keysWithSameValue([
6868
'beUrl',
6969
'instanceName',
70-
'footerText'
70+
'footerText',
71+
'tiebaImageProxy'
7172
], '')
7273
}
7374
});

fe/src/utils/post/renderer/content.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
export const extractContentTexts = (content?: PostContent | null) => content
22
?.reduce((acc, i) => acc + ('text' in i ? i.text ?? '' : ''), '') ?? '';
33
export const toHTTPS = (url?: string) => url?.replace('http://', 'https://');
4-
export const imageUrl = (originSrc?: string) =>
5-
(originSrc !== undefined && /^(?:[0-9a-f]{40}|[0-9a-f]{24})$/u.test(originSrc)
6-
? `https://imgsrc.baidu.com/forum/pic/item/${originSrc}.jpg`
7-
: originSrc);
4+
const config = useRuntimeConfig().public;
5+
export const imageUrl = (originSrc?: string) => {
6+
if (originSrc === undefined || !/^(?:[0-9a-f]{40}|[0-9a-f]{24})$/u.test(originSrc))
7+
return originSrc;
8+
if (config.tiebaImageProxy !== '')
9+
return `${config.tiebaImageProxy}/${originSrc}`;
10+
11+
return `https://imgsrc.baidu.com/forum/pic/item/${originSrc}.jpg`;
12+
};
813
export const tryExtractTiebaOutboundUrl = (rawURL?: string) => {
914
const url = new URL(rawURL ?? '');
1015
if (url.hostname === 'tieba.baidu.com' && url.pathname === '/mo/q/checkurl')

0 commit comments

Comments
 (0)