@@ -213,6 +213,81 @@ const cleanRawDynamicObservation = (dynamic: any, data: any) => {
213213 }
214214}
215215
216+ // 站点自身的「品牌识别」抑制:当用户就在 github.com 时不再把 GitHub.com 当作一项「使用了的技术」
217+ // 显示给他,那是 URL 栏里已经告诉他的事情
218+ const SELF_HOST_SUPPRESS : Record < string , readonly string [ ] > = {
219+ 'github.com' : [ 'GitHub.com' , 'GitHub' ] ,
220+ 'gitlab.com' : [ 'GitLab.com' , 'GitLab' ] ,
221+ 'bitbucket.org' : [ 'Bitbucket' ] ,
222+ 'codeberg.org' : [ 'Codeberg' ] ,
223+ 'gitee.com' : [ 'Gitee' ] ,
224+ 'huggingface.co' : [ 'Hugging Face' ] ,
225+ 'stackoverflow.com' : [ 'Stack Overflow' ] ,
226+ 'stackexchange.com' : [ 'Stack Exchange' ] ,
227+ 'npmjs.com' : [ 'npm' , 'npm 包注册中心' ] ,
228+ 'pypi.org' : [ 'PyPI' ] ,
229+ 'crates.io' : [ 'crates.io' ] ,
230+ 'rubygems.org' : [ 'RubyGems' ] ,
231+ 'packagist.org' : [ 'Packagist' ] ,
232+ 'twitter.com' : [ 'Twitter' , 'X (Twitter)' ] ,
233+ 'x.com' : [ 'Twitter' , 'X (Twitter)' ] ,
234+ 'facebook.com' : [ 'Facebook' ] ,
235+ 'instagram.com' : [ 'Instagram' ] ,
236+ 'linkedin.com' : [ 'LinkedIn' ] ,
237+ 'youtube.com' : [ 'YouTube' ] ,
238+ 'tiktok.com' : [ 'TikTok' ] ,
239+ 'reddit.com' : [ 'Reddit' ] ,
240+ 'discord.com' : [ 'Discord' ] ,
241+ 'slack.com' : [ 'Slack' ] ,
242+ 'telegram.org' : [ 'Telegram' ] ,
243+ 'whatsapp.com' : [ 'WhatsApp' ] ,
244+ 'medium.com' : [ 'Medium' ] ,
245+ 'substack.com' : [ 'Substack' ] ,
246+ 'notion.so' : [ 'Notion' ] ,
247+ 'figma.com' : [ 'Figma' ] ,
248+ 'linear.app' : [ 'Linear' ] ,
249+ 'asana.com' : [ 'Asana' ] ,
250+ 'trello.com' : [ 'Trello' ] ,
251+ 'monday.com' : [ 'monday.com' , 'Monday' ] ,
252+ 'airtable.com' : [ 'Airtable' ] ,
253+ 'shopify.com' : [ 'Shopify Admin' ] ,
254+ 'replit.com' : [ 'Replit' ] ,
255+ 'codepen.io' : [ 'CodePen' ] ,
256+ 'stackblitz.com' : [ 'StackBlitz' ] ,
257+ 'codesandbox.io' : [ 'CodeSandbox' ] ,
258+ 'jsfiddle.net' : [ 'JSFiddle' ] ,
259+ 'google.com' : [ 'Google Search' ] ,
260+ 'bing.com' : [ 'Bing' ] ,
261+ 'duckduckgo.com' : [ 'DuckDuckGo' ] ,
262+ 'baidu.com' : [ '百度' , 'Baidu' ] ,
263+ 'zhihu.com' : [ '知乎' , 'Zhihu' ] ,
264+ 'weibo.com' : [ '微博' , 'Weibo' ] ,
265+ 'bilibili.com' : [ '哔哩哔哩' , 'Bilibili' ]
266+ }
267+
268+ const extractRegistrableHost = ( url : string ) : string => {
269+ try {
270+ return new URL ( url ) . hostname . toLowerCase ( ) . replace ( / ^ w w w \. / , '' )
271+ } catch {
272+ return ''
273+ }
274+ }
275+
276+ const suppressSelfHostTechs = ( technologies : any [ ] , pageUrl : string ) : any [ ] => {
277+ const host = extractRegistrableHost ( pageUrl )
278+ if ( ! host ) return technologies
279+ // 主域匹配:github.com 时也抑制;gist.github.com 时按完整 host 找不到,回退取末两段
280+ const parts = host . split ( '.' )
281+ const candidates = [ host , parts . slice ( - 2 ) . join ( '.' ) ]
282+ const suppressNames = new Set < string > ( )
283+ for ( const candidate of candidates ) {
284+ const list = SELF_HOST_SUPPRESS [ candidate ]
285+ if ( list ) for ( const name of list ) suppressNames . add ( name )
286+ }
287+ if ( ! suppressNames . size ) return technologies
288+ return technologies . filter ( tech => ! suppressNames . has ( String ( tech ?. name || '' ) ) )
289+ }
290+
216291const buildDisplayTechnologies = ( data : any , settings : any ) => {
217292 const all : any [ ] = [ ]
218293 addAllTechnologies ( all , data . page ?. technologies )
@@ -249,7 +324,11 @@ const buildDisplayTechnologies = (data: any, settings: any) => {
249324 source : tech . source || 'JS 版权注释'
250325 } ) )
251326 )
252- return filterTechnologiesBySettings ( suppressGenericCdnFallbacks ( mergeDisplayTechnologyRecords ( all ) ) , settings )
327+ const pageUrl = data . page ?. url || data . dynamic ?. url || data . main ?. url || ''
328+ return filterTechnologiesBySettings (
329+ suppressSelfHostTechs ( suppressGenericCdnFallbacks ( mergeDisplayTechnologyRecords ( all ) ) , pageUrl ) ,
330+ settings
331+ )
253332}
254333
255334const buildPopupResult = async ( data : any , settings : any , tab : any ) => {
0 commit comments