优化sitmap
This commit is contained in:
parent
5196564428
commit
2f1fc8d285
@ -36,7 +36,7 @@ ${entries.map(entry => ` <url>
|
|||||||
</urlset>`;
|
</urlset>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成XSLT样式表
|
// 生成XSLT样式表 - 简化版直接嵌入解码后的URL
|
||||||
function generateXsltStylesheet(entries) {
|
function generateXsltStylesheet(entries) {
|
||||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<xsl:stylesheet version="1.0"
|
<xsl:stylesheet version="1.0"
|
||||||
@ -52,200 +52,114 @@ function generateXsltStylesheet(entries) {
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
body {
|
/* 基础样式 */
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
:root {
|
||||||
line-height: 1.6;
|
--background: #fff;
|
||||||
color: #333;
|
--text: #222;
|
||||||
max-width: 1200px;
|
--link: #0366d6;
|
||||||
margin: 0 auto;
|
--border: #eee;
|
||||||
padding: 20px;
|
--header-bg: #f8f9fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 深色模式 */
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
body {
|
:root {
|
||||||
background-color: #1a1a1a;
|
--background: #121212;
|
||||||
color: #f0f0f0;
|
--text: #eee;
|
||||||
}
|
--link: #58a6ff;
|
||||||
a {
|
--border: #333;
|
||||||
color: #4da6ff;
|
--header-bg: #222;
|
||||||
}
|
|
||||||
a:visited {
|
|
||||||
color: #c58fff;
|
|
||||||
}
|
|
||||||
.table {
|
|
||||||
border-color: #444;
|
|
||||||
}
|
|
||||||
.table th, .table td {
|
|
||||||
border-color: #444;
|
|
||||||
}
|
|
||||||
.table thead th {
|
|
||||||
background-color: #2a2a2a;
|
|
||||||
}
|
|
||||||
.table tbody tr:nth-child(odd) {
|
|
||||||
background-color: #252525;
|
|
||||||
}
|
|
||||||
.table tbody tr:hover {
|
|
||||||
background-color: #303030;
|
|
||||||
}
|
|
||||||
.stat-box {
|
|
||||||
background-color: #2a2a2a;
|
|
||||||
}
|
|
||||||
.copy-btn {
|
|
||||||
background-color: #2a2a2a;
|
|
||||||
color: #f0f0f0;
|
|
||||||
border: 1px solid #444;
|
|
||||||
}
|
|
||||||
.copy-btn:hover {
|
|
||||||
background-color: #3a3a3a;
|
|
||||||
}
|
|
||||||
.copy-btn:active {
|
|
||||||
background-color: #4a4a4a;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, system-ui, sans-serif;
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--text);
|
||||||
|
margin: 0;
|
||||||
|
padding: 20px;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.page-header {
|
.page-header {
|
||||||
|
background: var(--header-bg);
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
gap: 5px;
|
||||||
margin-bottom: 20px;
|
border: 1px solid var(--border);
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--text);
|
||||||
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-title {
|
.copy-icon {
|
||||||
margin: 0;
|
width: 16px;
|
||||||
font-size: 2.2rem;
|
height: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
.copy-btn.success {
|
||||||
margin-top: 0;
|
background: #28a745;
|
||||||
font-size: 2.2rem;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta {
|
/* 表格样式 - 最关键部分 */
|
||||||
margin-bottom: 20px;
|
.table-container {
|
||||||
font-size: 0.9rem;
|
width: 100%;
|
||||||
color: #666;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table {
|
.table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
margin-bottom: 30px;
|
margin-top: 20px;
|
||||||
table-layout: fixed;
|
min-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table th, .table td {
|
.table th, .table td {
|
||||||
padding: 10px 15px;
|
padding: 10px;
|
||||||
border: 1px solid #ddd;
|
border-bottom: 1px solid var(--border);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
overflow: hidden;
|
white-space: nowrap; /* 防止URL换行 */
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.table thead th {
|
.table th {
|
||||||
background-color: #f5f5f5;
|
background: var(--header-bg);
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table tbody tr:nth-child(odd) {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table tbody tr:hover {
|
|
||||||
background-color: #f0f0f0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.url {
|
.url {
|
||||||
word-break: break-all;
|
width: 85%;
|
||||||
width: 80%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.priority {
|
.priority {
|
||||||
width: 20%;
|
width: 15%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats {
|
.table a {
|
||||||
display: flex;
|
color: var(--link);
|
||||||
gap: 20px;
|
text-decoration: none;
|
||||||
flex-wrap: wrap;
|
}
|
||||||
|
|
||||||
|
.table a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 其他组件样式 */
|
||||||
|
.meta {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stat-box {
|
|
||||||
padding: 15px;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
border-radius: 5px;
|
|
||||||
flex: 1;
|
|
||||||
min-width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stat-box h3 {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
font-size: 1rem;
|
|
||||||
color: #666;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stat-box p {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer {
|
|
||||||
margin-top: 30px;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
color: #666;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.table {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.page-header {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn {
|
|
||||||
padding: 8px 16px;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.2s, transform 0.1s;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn:hover {
|
|
||||||
background-color: #e5e5e5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn:active {
|
|
||||||
background-color: #d5d5d5;
|
|
||||||
transform: translateY(1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn.success {
|
|
||||||
background-color: #4caf50;
|
|
||||||
color: white;
|
|
||||||
border-color: #4caf50;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-icon {
|
|
||||||
width: 14px;
|
|
||||||
height: 14px;
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
@ -255,7 +169,7 @@ function generateXsltStylesheet(entries) {
|
|||||||
const urls = [];
|
const urls = [];
|
||||||
|
|
||||||
// 收集所有URL
|
// 收集所有URL
|
||||||
document.querySelectorAll('#sitemap-table tbody a').forEach(function(link) {
|
document.querySelectorAll('.table-container #sitemap-table tbody a').forEach(function(link) {
|
||||||
urls.push(link.textContent.trim());
|
urls.push(link.textContent.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -305,69 +219,43 @@ function generateXsltStylesheet(entries) {
|
|||||||
<p>此网站地图包含 <xsl:value-of select="count(sitemap:urlset/sitemap:url)" /> 个 URL</p>
|
<p>此网站地图包含 <xsl:value-of select="count(sitemap:urlset/sitemap:url)" /> 个 URL</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="stats">
|
<div class="table-container" style="overflow-x: auto;">
|
||||||
<div class="stat-box">
|
<table id="sitemap-table" class="table">
|
||||||
<h3>总页面数</h3>
|
<thead>
|
||||||
<p><xsl:value-of select="count(sitemap:urlset/sitemap:url)" /></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table id="sitemap-table" class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="url">URL</th>
|
|
||||||
<th class="priority">优先级</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
|
||||||
<xsl:sort select="sitemap:priority" order="descending" />
|
|
||||||
<xsl:variable name="url" select="sitemap:loc/text()" />
|
|
||||||
<xsl:variable name="decodedUrl">
|
|
||||||
<xsl:call-template name="decode-url">
|
|
||||||
<xsl:with-param name="url" select="$url" />
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:variable>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="url">
|
<th class="url">URL</th>
|
||||||
<a href="{$url}">
|
<th class="priority">优先级</th>
|
||||||
<xsl:value-of select="$decodedUrl" />
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td class="priority">
|
|
||||||
<xsl:value-of select="sitemap:priority" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</xsl:for-each>
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
<!-- 直接内联解码后的URL映射 -->
|
||||||
|
${entries.map(entry => `<xsl:variable name="urlMap_${entry.url.replace(/[^a-zA-Z0-9]/g, '_')}" select="'${escapeXml(entry.url)}'" />`).join('\n ')}
|
||||||
|
|
||||||
<div class="footer">
|
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
||||||
<p>此网站地图使用 XSLT 样式表生成,既适合搜索引擎索引,又方便人类阅读</p>
|
<xsl:sort select="sitemap:priority" order="descending" />
|
||||||
|
<xsl:variable name="url" select="sitemap:loc/text()" />
|
||||||
|
<tr>
|
||||||
|
<td class="url">
|
||||||
|
<a href="{$url}">
|
||||||
|
<!-- 使用直接构建时生成的解码URL -->
|
||||||
|
${entries.map((entry, index) =>
|
||||||
|
index === 0
|
||||||
|
? `<xsl:if test="$url = '${escapeXml(entry.url)}'"><xsl:value-of select="'${escapeXml(entry.decodedUrl)}'" /></xsl:if>`
|
||||||
|
: `<xsl:if test="$url = '${escapeXml(entry.url)}'"><xsl:value-of select="'${escapeXml(entry.decodedUrl)}'" /></xsl:if>`
|
||||||
|
).join('\n ')}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="priority">
|
||||||
|
<xsl:value-of select="sitemap:priority" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</xsl:for-each>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<!-- 自定义URL解码模板 -->
|
|
||||||
<xsl:template name="decode-url">
|
|
||||||
<xsl:param name="url" />
|
|
||||||
<!-- 直接输出预先解码的URL映射 -->
|
|
||||||
<xsl:variable name="urlKey" select="$url" />
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="document('')/*/xsl:variable[@name='url-mapping']/url[@key=$urlKey]">
|
|
||||||
<xsl:value-of select="document('')/*/xsl:variable[@name='url-mapping']/url[@key=$urlKey]/@decoded" />
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<xsl:value-of select="$url" />
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- URL映射变量 -->
|
|
||||||
<xsl:variable name="url-mapping">
|
|
||||||
${entries.map(entry => `<url key="${escapeXml(entry.url)}" decoded="${escapeXml(entry.decodedUrl)}" />`).join('\n ')}
|
|
||||||
</xsl:variable>
|
|
||||||
</xsl:stylesheet>`;
|
</xsl:stylesheet>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user