@waline/client
Advanced tools
Comparing version 2.10.0 to 2.11.0
@@ -124,2 +124,12 @@ interface WalineEmojiInfo { | ||
hottest: string; | ||
reactionTitle: string; | ||
reaction0: string; | ||
reaction1: string; | ||
reaction2: string; | ||
reaction3: string; | ||
reaction4: string; | ||
reaction5: string; | ||
reaction6: string; | ||
reaction7: string; | ||
reaction8: string; | ||
} | ||
@@ -319,2 +329,6 @@ | ||
recaptchaV3Key?: string; | ||
/** | ||
* reaction | ||
*/ | ||
reaction?: string[] | boolean; | ||
} | ||
@@ -321,0 +335,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){if("function"==typeof define&&define.amd)define("Waline",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.Waline=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.pageviewCount=void 0;e.version="2.10.0";const t=e=>{const t=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").replace(/\/$/u,"")}(e);return/^(https?:)?\/\//.test(t)?t:`https://${t}`},n=e=>{"AbortError"!==e.name&&console.error(e.message)},r={"Content-Type":"application/json"},o=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if("object"==typeof e&&e.errno)throw new TypeError(`Fetch ${t} failed with ${e.errno}: ${e.errmsg}`);return e},i=e=>{let{serverURL:t,lang:n,paths:r,signal:i}=e;return fetch(`${t}/article?path=${encodeURIComponent(r.join(","))}&lang=${n}`,{signal:i}).then((e=>e.json())).then((e=>o(e,"visit count"))).then((e=>Array.isArray(e)?e:[e]))},a=e=>{let{serverURL:t,lang:n,path:i}=e;return fetch(`${t}/article?lang=${n}`,{method:"POST",headers:r,body:JSON.stringify({path:i})}).then((e=>e.json())).then((e=>o(e,"visit count")))},l=e=>e.dataset.path||e.getAttribute("id"),s=(e,t)=>{t.forEach(((t,n)=>{t.innerText=e[n].toString()}))};e.pageviewCount=e=>{let{serverURL:r,path:o=window.location.pathname,selector:h=".waline-pageview-count",update:p=!0,lang:f="zh-CN"}=e;const c=new AbortController,u=Array.from(document.querySelectorAll(h)),d=e=>{const t=l(e);return null!==t&&o!==t},g=e=>i({serverURL:t(r),paths:e.map((e=>l(e)||o)),lang:f,signal:c.signal}).then((t=>s(t,e))).catch(n);if(p){const e=u.filter((e=>!d(e))),n=u.filter(d);a({serverURL:t(r),path:o,lang:f}).then((t=>s(new Array(e.length).fill(t),e))),n.length&&g(n)}else g(u);return c.abort.bind(c)}})); | ||
!function(e,t){if("function"==typeof define&&define.amd)define("Waline",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.Waline=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.pageviewCount=void 0;e.version="2.11.0";const t=e=>{const t=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").replace(/\/$/u,"")}(e);return/^(https?:)?\/\//.test(t)?t:`https://${t}`},n=e=>{"AbortError"!==e.name&&console.error(e.message)},r={"Content-Type":"application/json"},o=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if("object"==typeof e&&e.errno)throw new TypeError(`Fetch ${t} failed with ${e.errno}: ${e.errmsg}`);return e},a=e=>{let{serverURL:t,lang:n,paths:r,signal:a}=e;return(e=>{let{serverURL:t,lang:n,paths:r,type:a,signal:i}=e;return fetch(`${t}/article?path=${encodeURIComponent(r.join(","))}&type=${encodeURIComponent(a.join(","))}&lang=${n}`,{signal:i}).then((e=>e.json())).then((e=>o(e,"article count")))})({serverURL:t,lang:n,paths:r,type:["time"],signal:a}).then((e=>Array.isArray(e)?e:[e]))},i=e=>(e=>{let{serverURL:t,lang:n,path:a,type:i,action:l}=e;return fetch(`${t}/article?lang=${n}`,{method:"POST",headers:r,body:JSON.stringify({path:a,type:i,action:l})}).then((e=>e.json())).then((e=>o(e,"article count")))})({...e,type:"time"}),l=e=>e.dataset.path||e.getAttribute("id"),s=(e,t)=>{t.forEach(((t,n)=>{t.innerText=e[n].toString()}))};e.pageviewCount=e=>{let{serverURL:r,path:o=window.location.pathname,selector:p=".waline-pageview-count",update:h=!0,lang:c="zh-CN"}=e;const f=new AbortController,g=Array.from(document.querySelectorAll(p)),u=e=>{const t=l(e);return null!==t&&o!==t},d=e=>a({serverURL:t(r),paths:e.map((e=>l(e)||o)),lang:c,signal:f.signal}).then((t=>s(t,e))).catch(n);if(h){const e=g.filter((e=>!u(e))),n=g.filter(u);i({serverURL:t(r),path:o,lang:c}).then((t=>s(new Array(e.length).fill(t),e))),n.length&&d(n)}else d(g);return f.abort.bind(f)}})); | ||
//# sourceMappingURL=pageview.js.map |
@@ -201,2 +201,12 @@ interface WalineEmojiInfo { | ||
hottest: string; | ||
reactionTitle: string; | ||
reaction0: string; | ||
reaction1: string; | ||
reaction2: string; | ||
reaction3: string; | ||
reaction4: string; | ||
reaction5: string; | ||
reaction6: string; | ||
reaction7: string; | ||
reaction8: string; | ||
} | ||
@@ -396,2 +406,6 @@ | ||
recaptchaV3Key?: string; | ||
/** | ||
* reaction | ||
*/ | ||
reaction?: string[] | boolean; | ||
} | ||
@@ -398,0 +412,0 @@ |
{ | ||
"name": "@waline/client", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"description": "client for waline comment system", | ||
@@ -114,7 +114,7 @@ "keywords": [ | ||
"@types/marked": "4.0.7", | ||
"@types/node": "18.7.18", | ||
"@types/node": "18.7.21", | ||
"@vitejs/plugin-vue": "3.1.0", | ||
"recaptcha-v3": "^1.10.0", | ||
"recaptcha-v3": "1.10.0", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.79.0", | ||
"rollup": "2.79.1", | ||
"rollup-plugin-dts": "4.2.2", | ||
@@ -124,3 +124,3 @@ "rollup-plugin-terser": "7.0.2", | ||
"typescript": "4.8.3", | ||
"vite": "3.1.2" | ||
"vite": "3.1.3" | ||
}, | ||
@@ -127,0 +127,0 @@ "engines": { |
@@ -118,1 +118,10 @@ import type { WalineMeta, WalineSearchOptions } from '../typings'; | ||
}; | ||
export const defaultReaction = [ | ||
'//unpkg.com/@waline/emojis/tieba/tieba_agree.png', | ||
'//unpkg.com/@waline/emojis/tieba/tieba_look_down.png', | ||
'//unpkg.com/@waline/emojis/tieba/tieba_sunglasses.png', | ||
'//unpkg.com/@waline/emojis/tieba/tieba_pick_nose.png', | ||
'//unpkg.com/@waline/emojis/tieba/tieba_awkward.png', | ||
'//unpkg.com/@waline/emojis/tieba/tieba_sleep.png', | ||
]; |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'Hottest', | ||
'What do you think?', | ||
]); |
@@ -52,2 +52,3 @@ import type { WalineLocale } from '../../typings'; | ||
'hottest', | ||
'reactionTitle', | ||
]; | ||
@@ -54,0 +55,0 @@ |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'人気順', | ||
'どう思いますか?', | ||
]); |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'Mais quente', | ||
'O que você acha?', | ||
]); |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'самый горячий', | ||
'Что вы думаете?', | ||
]); |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'nóng nhất', | ||
'What do you think?', | ||
]); |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'按热度', | ||
'你认为这篇文章怎么样?', | ||
]); |
@@ -52,2 +52,3 @@ import { generateLocale } from './generate'; | ||
'按熱度', | ||
'你認為這篇文章怎麼樣?', | ||
]); |
@@ -49,2 +49,12 @@ export interface WalineDateLocale { | ||
hottest: string; | ||
reactionTitle: string; | ||
reaction0: string; | ||
reaction1: string; | ||
reaction2: string; | ||
reaction3: string; | ||
reaction4: string; | ||
reaction5: string; | ||
reaction6: string; | ||
reaction7: string; | ||
reaction8: string; | ||
} |
@@ -220,3 +220,8 @@ import type { | ||
*/ | ||
recaptchaV3Key?: string; | ||
recaptchaV3Key?: string; | ||
/** | ||
* reaction | ||
*/ | ||
reaction?: string[] | boolean; | ||
} |
import { | ||
defaultLang, | ||
defaultLocales, | ||
defaultReaction, | ||
defaultUploadImage, | ||
@@ -25,3 +26,4 @@ defaultHighlighter, | ||
export interface WalineConfig extends Required<Omit<WalineProps, 'wordLimit' | 'recaptchaV3Key'>> { | ||
export interface WalineConfig | ||
extends Required<Omit<WalineProps, 'wordLimit' | 'recaptchaV3Key'>> { | ||
locale: WalineLocale; | ||
@@ -67,2 +69,3 @@ wordLimit: [number, number] | false; | ||
search = getDefaultSearchOptions(), | ||
reaction, | ||
...more | ||
@@ -89,3 +92,4 @@ }: WalineProps): WalineConfig => ({ | ||
search, | ||
reaction: reaction === true ? defaultReaction : reaction || false, | ||
...more, | ||
}); |
@@ -16,4 +16,3 @@ import type { WalineComment, WalineCommentData } from '../typings'; | ||
throw new TypeError( | ||
`Fetch ${name} failed with ${(data as FetchErrorData).errno}: ${ | ||
(data as FetchErrorData).errmsg | ||
`Fetch ${name} failed with ${(data as FetchErrorData).errno}: ${(data as FetchErrorData).errmsg | ||
}` | ||
@@ -236,43 +235,78 @@ ); | ||
export interface FetchPageviewsOptions { | ||
export interface FetchArticleCounterOptions { | ||
serverURL: string; | ||
lang: string; | ||
paths: string[]; | ||
type: string[]; | ||
signal: AbortSignal; | ||
} | ||
export const fetchPageviews = ({ | ||
export const fetchArticleCounter = ({ | ||
serverURL, | ||
lang, | ||
paths, | ||
type, | ||
signal, | ||
}: FetchPageviewsOptions): Promise<number[]> => | ||
}: FetchArticleCounterOptions): Promise< | ||
Record<string, number>[] | Record<string, number> | number[] | number | ||
> => | ||
fetch( | ||
`${serverURL}/article?path=${encodeURIComponent( | ||
paths.join(',') | ||
)}&lang=${lang}`, | ||
)}&type=${encodeURIComponent(type.join(','))}&lang=${lang}`, | ||
{ signal } | ||
) | ||
.then((resp) => resp.json() as Promise<number[] | number>) | ||
.then((data) => errorCheck(data, 'visit count')) | ||
.then( | ||
(resp) => | ||
resp.json() as Promise<Record<string, number>[] | number[] | number> | ||
) | ||
.then((data) => errorCheck(data, 'article count')); | ||
export const fetchPageviews = ({ | ||
serverURL, | ||
lang, | ||
paths, | ||
signal, | ||
}: Omit<FetchArticleCounterOptions, 'type'>): Promise<number[]> => | ||
fetchArticleCounter({ | ||
serverURL, | ||
lang, | ||
paths, | ||
type: ['time'], | ||
signal, | ||
}) | ||
// TODO: Improve this API | ||
.then((counts) => (Array.isArray(counts) ? counts : [counts])); | ||
.then((counts) => (Array.isArray(counts) ? counts : [counts])) as Promise< | ||
number[] | ||
>; | ||
export interface UpdatePageviewsOptions { | ||
export interface UpdateArticleCounterOptions { | ||
serverURL: string; | ||
lang: string; | ||
path: string; | ||
type: string; | ||
action?: 'inc' | 'desc'; | ||
} | ||
export const updatePageviews = ({ | ||
export const updateArticleCounter = ({ | ||
serverURL, | ||
lang, | ||
path, | ||
}: UpdatePageviewsOptions): Promise<number> => | ||
type, | ||
action, | ||
}: UpdateArticleCounterOptions): Promise<number> => | ||
fetch(`${serverURL}/article?lang=${lang}`, { | ||
method: 'POST', | ||
headers: JSON_HEADERS, | ||
body: JSON.stringify({ path }), | ||
body: JSON.stringify({ path, type, action }), | ||
}) | ||
.then((resp) => resp.json() as Promise<number>) | ||
.then((data) => errorCheck(data, 'visit count')); | ||
.then((data) => errorCheck(data, 'article count')); | ||
export const updatePageviews = ( | ||
options: Omit<UpdateArticleCounterOptions, 'type'> | ||
): Promise<number> => | ||
updateArticleCounter({ | ||
...options, | ||
type: 'time', | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2200344
114
7237
87