@@ -51,12 +51,18 @@ function customTagCloudHelper(options) {
5151 return '' ;
5252 }
5353
54+ // 全てのタグの完全な情報をMapに保存し、信頼できるデータソースとする
55+ const tagDataMap = new Map ( ) ;
56+ site . tags . forEach ( t => {
57+ tagDataMap . set ( t . name , t ) ;
58+ } ) ;
59+
5460 // オプションのデフォルト値を設定
5561 options = options || { } ;
5662 const minFont = options . min_font || 12 ;
5763 const maxFont = options . max_font || 26 ;
5864 const fontUnit = options . font_unit || 'px' ;
59- const boostRatio = options . boost_ratio || 0.7 ; // 上昇ペースのオプション
65+ const boostRatio = options . boost_ratio || 0.7 ;
6066
6167 const sizes = tags . map ( tag => tag . length ) ;
6268 const maxSize = Math . max ( ...sizes ) || 1 ;
@@ -66,21 +72,32 @@ function customTagCloudHelper(options) {
6672 let result = '' ;
6773
6874 tags . forEach ( tag => {
69- // 1. 基本となる線形の比率(0.0 〜 1.0)を算出
75+ // フォントサイズの計算
7076 const ratio = spread === 0 ? 0.5 : ( tag . length - minSize ) / spread ;
71-
72- // 2. 比率を累乗して上昇ペースを調整 (boostRatio乗する)
73- // boostRatioが 0.5 の場合、平方根と同じ効果になり、序盤の上昇が急になります。
7477 const adjustedRatio = Math . pow ( ratio , boostRatio ) ;
75-
76- // 3. 調整後の比率を元にフォントサイズを決定
7778 const fontSize = minFont + ( maxFont - minFont ) * adjustedRatio ;
7879
7980 let tagName = tag . name ;
81+ let suffix = '' ;
82+
83+ // suffix(* または **)を決定するロジック
8084 if ( tag . length === 1 ) {
81- tagName += '*' ; // 記事数が1なら「*」を追記
85+ // 記事数が1つのタグは「*」を付ける
86+ suffix = '*' ;
87+ const singlePost = tag . posts . first ( ) ;
88+
89+ // その記事に紐づく他のタグが、1つでも他の記事に紐づかないタグの場合、「**」を付与する
90+ const otherTags = singlePost . tags . filter ( t => t . name !== tag . name ) ;
91+ if ( otherTags . length > 0 && otherTags . some ( otherTag => {
92+ const fullTagInfo = tagDataMap . get ( otherTag . name ) ;
93+ return fullTagInfo && fullTagInfo . length === 1 ;
94+ } ) ) {
95+ suffix = '**' ;
96+ }
8297 }
8398
99+ tagName += suffix ;
100+
84101 tagName = tagName . replace ( / / g, '-' ) ;
85102 const tagLink = hexo . url_for ( tag . path ) ;
86103
0 commit comments