Skip to content

Commit

Permalink
✨ feat: apply XML styling
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Nov 13, 2023
1 parent 741a7e7 commit a5fb25a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ tabi has a perfect score on Google's Lighthouse audit:
- [X] Support for [comments using giscus, utterances, Hyvor Talk, or Isso](https://welpo.github.io/tabi/blog/comments/).
- [X] Code syntax highlighting with colours based on [Catppuccin](https://github.com/catppuccin/catppuccin) Frappé.
- [X] [KaTeX](https://katex.org/) support for mathematical notation.
- [X] [Stylized and human readable Atom feed](https://welpo.github.io/tabi/atom.xml).
- [X] [Stylized and human readable sitemap](https://welpo.github.io/tabi/sitemap.xml).
- [X] [Mail encoding](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#encoded-email) for spam protection.
- [X] All JavaScript can be [fully disabled](https://welpo.github.io/tabi/blog/javascript/).
- [X] [Customizable Table of Contents](https://welpo.github.io/tabi/blog/toc/).
Expand All @@ -40,7 +42,6 @@ tabi has a perfect score on Google's Lighthouse audit:
- [X] Responsive design.
- [X] [Projects page](https://welpo.github.io/tabi/projects/).
- [X] [Archive page](https://welpo.github.io/tabi/archive/).
- [X] [Stylized feed](https://welpo.github.io/tabi/atom.xml).
- [X] [Social links](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#social-media-icons).
- [X] [Tags](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#tags).

Expand Down
3 changes: 2 additions & 1 deletion content/projects/tabi/index.ca.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ social_media_card = "social_cards/ca_projects_tabi.jpg"
- Suport per a [comentaris usant giscus, utterances, Hyvor Talk o Isso](https://welpo.github.io/tabi/ca/blog/comments/).
- Tot el JavaScript es pot [deshabilitar completament](https://welpo.github.io/tabi/ca/blog/javascript/).
- [Codificació de correu](https://welpo.github.io/tabi/ca/blog/mastering-tabi-settings/#correu-electronic-codificat) per a protecció contra spam.
- [Mapa del lloc estilitzat i llegible per humans](https://welpo.github.io/tabi/sitemap.xml).
- [Capçaleres de seguretat personalitzables](https://welpo.github.io/tabi/ca/blog/security/).
- [Feed Atom estilitzat i llegible per humans](https://welpo.github.io/tabi/ca/atom.xml).
- [Enllaços de retrocés per a notes al peu](https://welpo.github.io/tabi/ca/blog/mastering-tabi-settings/#enllacos-de-retorn-a-les-notes-a-peu-de-pagina).
- [Taula de continguts personalitzable](https://welpo.github.io/tabi/ca/blog/toc/).
- [Avís de drets d'autor personalitzat](https://welpo.github.io/tabi/ca/blog/mastering-tabi-settings/#copyright).
Expand All @@ -41,7 +43,6 @@ social_media_card = "social_cards/ca_projects_tabi.jpg"
- Suport de [KaTeX](https://katex.org/).
- [Enllaços socials](https://welpo.github.io/tabi/ca/blog/mastering-tabi-settings/#icones-de-xarxes-socials).
- [Pàgina d'arxiu](https://welpo.github.io/tabi/ca/archive/).
- [Feed estilitzat](https://welpo.github.io/tabi/ca/atom.xml).
- [Etiquetes](https://welpo.github.io/tabi/ca/blog/mastering-tabi-settings/#etiquetes).

## Pràctiques de desenvolupament
Expand Down
3 changes: 2 additions & 1 deletion content/projects/tabi/index.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ social_media_card = "social_cards/es_projects_tabi.jpg"
- Soporte para [comentarios usando giscus, utterances, Hyvor Talk o Isso](https://welpo.github.io/tabi/es/blog/comments/).
- Todo el JavaScript se puede [deshabilitar completamente](https://welpo.github.io/tabi/es/blog/javascript/).
- [Codificación de correo](https://welpo.github.io/tabi/es/blog/mastering-tabi-settings/#encoded-email) para protección contra spam.
- [Mapa de sitio web estilizado y legible por humanos](https://welpo.github.io/tabi/sitemap.xml).
- [Feed de Atom estilizado y legible por humanos](https://welpo.github.io/tabi/es/atom.xml).
- [Aviso de derechos de autor personalizado](https://welpo.github.io/tabi/es/blog/mastering-tabi-settings/#copyright).
- [Cabeceras de seguridad personalizables](https://welpo.github.io/tabi/es/blog/security/).
- [Botón de copiar para bloques de código](https://welpo.github.io/tabi/es/blog/mastering-tabi-settings/#boton-de-copiar-en-bloques-de-codigo).
Expand All @@ -41,7 +43,6 @@ social_media_card = "social_cards/es_projects_tabi.jpg"
- Soporte de [KaTeX](https://katex.org/).
- [Página de archivo](https://welpo.github.io/tabi/es/archive/).
- [Enlaces sociales](https://welpo.github.io/tabi/es/blog/mastering-tabi-settings/#iconos-de-redes-sociales).
- [Feed estilizado](https://welpo.github.io/tabi/es/atom.xml).
- [Etiquetas](https://welpo.github.io/tabi/es/blog/mastering-tabi-settings/#tags).

## Prácticas de desarrollo
Expand Down
3 changes: 2 additions & 1 deletion content/projects/tabi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ social_media_card = "social_cards/projects_tabi.jpg"
- Support for [comments using giscus, utterances, Hyvor Talk, or Isso](https://welpo.github.io/tabi/blog/comments/).
- Code syntax highlighting with colours based on [Catppuccin](https://github.com/catppuccin/catppuccin) Frappé.
- [KaTeX](https://katex.org/) support for mathematical notation.
- [Stylized and human readable Atom feed](https://welpo.github.io/tabi/atom.xml).
- [Stylized and human readable sitemap](https://welpo.github.io/tabi/sitemap.xml).
- [Mail encoding](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#encoded-email) for spam protection.
- All JavaScript can be [fully disabled](https://welpo.github.io/tabi/blog/javascript/).
- [Customizable Table of Contents](https://welpo.github.io/tabi/blog/toc/).
Expand All @@ -41,7 +43,6 @@ social_media_card = "social_cards/projects_tabi.jpg"
- Responsive design.
- [Projects page](https://welpo.github.io/tabi/projects/).
- [Archive page](https://welpo.github.io/tabi/archive/).
- [Stylized feed](https://welpo.github.io/tabi/atom.xml).
- [Social links](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#social-media-icons).
- [Tags](https://welpo.github.io/tabi/blog/mastering-tabi-settings/#tags).

Expand Down
50 changes: 50 additions & 0 deletions static/js/sortTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var table = document.querySelector("#sitemapTable");
var headers = Array.from(table.querySelectorAll("th"));

headers.forEach(function (header, index) {
header.classList.add('sortable');
header.sortDirection = 'asc';
header.addEventListener("click", function () {
sortTable(index);
});
});

headers[0].innerText += ' ▲';
headers[0].sortDirection = 'desc';

function sortTable(index) {
var header = headers[index];
var direction = header.sortDirection;
var arrow = direction === 'asc' ? '▲' : '▼';
var existingArrow = header.innerText.match(/▲|▼/);
if (existingArrow) {
header.innerText = header.innerText.replace(existingArrow, '');
}
header.innerText = header.innerText + ' ' + arrow;

var rows = Array.from(table.querySelectorAll("tbody tr"));
rows.sort(function (rowA, rowB) {
var cellA = rowA.querySelectorAll("td")[index].innerText;
var cellB = rowB.querySelectorAll("td")[index].innerText;
var comparison = cellA.localeCompare(cellB);
return direction === 'asc' ? comparison : -comparison;
});

var fragment = new DocumentFragment();
rows.forEach(function (row) {
fragment.appendChild(row);
});
table.querySelector("tbody").appendChild(fragment);

// Hide arrows on other columns.
headers.forEach(function (header, i) {
if (i !== index) {
var existingArrow = header.innerText.match(/▲|▼/);
if (existingArrow) {
header.innerText = header.innerText.replace(existingArrow, '');
}
}
});

header.sortDirection = direction === 'asc' ? 'desc' : 'asc';
}
1 change: 1 addition & 0 deletions static/js/sortTable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions static/sitemap_style.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html" encoding="UTF-8" indent="yes" />

<xsl:template match="/sitemap:urlset">
<html>
<head>
<title>Sitemap</title>
<link rel="stylesheet" href="/main.css"/>
<script src="/js/sortTable.min.js" defer="defer"></script>
</head>
<body>
<div class="full-width">
<h1>Sitemap</h1>
<p>Number of URLs: <xsl:value-of select="count(sitemap:url)"/></p>
<table id="sitemapTable" class="sitemap-table">
<thead>
<tr>
<th>URL</th>
<th>Last modification</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="sitemap:url">
<tr>
<td>
<a href="{sitemap:loc}">
<xsl:value-of select="sitemap:loc"/>
</a>
</td>
<td>
<xsl:value-of select="sitemap:lastmod"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
12 changes: 12 additions & 0 deletions templates/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="{{ get_url(path='/sitemap_style.xsl', trailing_slash=false) | safe }}" type="text/xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for sitemap_entry in entries %}
<url>
<loc>{{ sitemap_entry.permalink | escape_xml | safe }}</loc>
{%- if sitemap_entry.updated %}
<lastmod>{{ sitemap_entry.updated }}</lastmod>
{%- endif %}
</url>
{%- endfor %}
</urlset>

0 comments on commit a5fb25a

Please sign in to comment.