I am currently utilizing Array.map() to display a list of files in cache:
<div data-offline></div>
<script>
var version = 'v1:';
if (navigator && navigator.serviceWorker) {
caches.open(version + "pages").then(function (cache) {
cache.keys().then(function (keys) {
var offline = document.querySelector('[data-offline]');
offline.innerHTML =
"<ul class=\"li-list\">" +
keys.map(function(key) {
return '<li>› <a href="' + key.url + '">' + key.url + '</a></li>';
}).join('') +
"</ul>";
});
});
}
</script>
Thus, I have an overview of all html pages - given that the cache is specifically for html files - with their respective full URLs, such as "https://www.example.com/about/" etc.
My aim is to modify
<a href="' + key.url + '">' + key.url + '</a>
so that only the host (example.com) and pathname (/about/) are displayed within the text of the link
Unfortunately, I am unsure of how to carry out this implementation within this script.