feat(public): add top referers display to metrics summary

- Introduced a new section in the index.html to display the top referers with their respective counts.
- Implemented dynamic rendering of referers based on available data, enhancing user insights into traffic sources.
- Ensured the referers are sorted by count for better visibility and understanding of user access patterns.
This commit is contained in:
wood chen 2024-12-02 05:53:02 +08:00
parent b252b8313e
commit 32fb07a2ee

View File

@ -286,6 +286,23 @@
</div>
</div>
</div>
${Object.keys(data.top_referers).length > 0 ? `
<div class="stats-summary">
<div class="stats-header">
<h2>🔗 访问来源</h2>
</div>
<div class="referers-list">
${Object.entries(data.top_referers)
.sort(([,a], [,b]) => b - a)
.map(([referer, count]) => `
<div class="referer-item">
<span class="referer">${referer || '直接访问'}</span>
<span class="count">${count}</span>
</div>
`).join('')}
</div>
</div>
` : ''}
</div>
`;