-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
<div class="tocsection sourcelink"> | ||
<div class="tocsection sourcelink" data-depth="{{ html_page_depth }}" data-subfolder="{{ html_subfolder }}"> | ||
<a id="pdf-link" href="#" style="display: inline-block; padding: 0; margin: 0; line-height: 1.5; vertical-align: middle;"> | ||
<i class="fa-solid fa-file-pdf" style="margin-left: 0px; margin-right: 6px; margin-bottom: 3px; font-size: inherit; line-height: inherit; vertical-align: middle; display: inline-block; width: 1em; height: 1em;"></i>{{ ("Sækja PDF") }}</a> | ||
</div> | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", function() { | ||
// Get the current URL path | ||
var path = window.location.pathname; | ||
|
||
// Find the position of the <html> folder in the path | ||
var htmlFolderIndex = path.indexOf('/html/'); | ||
if (htmlFolderIndex === -1) { | ||
console.error("The 'html' folder was not found in the path."); | ||
return; | ||
} | ||
|
||
// Trim the path to start from the <html> folder | ||
var relativePath = path.substring(htmlFolderIndex + 6); | ||
|
||
// Split the relative path into parts | ||
var parts = relativePath.split('/').filter(function(part) { | ||
return part.length > 0; | ||
}); | ||
const linkElement = document.getElementById('pdf-link'); | ||
if (!linkElement) return; | ||
|
||
const tocSection = document.querySelector('.tocsection.sourcelink'); | ||
const depth = parseInt(tocSection.getAttribute('data-depth'), 10); | ||
const subfolder = tocSection.getAttribute('data-subfolder'); | ||
|
||
// Determine the PDF link based on the path parts | ||
var pdfLink = ""; | ||
if (parts.length === 0 || (parts.length === 1 && parts[0].endsWith('.html'))) { | ||
// If the path has no parts or only one part that ends with .html, it is in the root folder | ||
pdfLink = "RUBIK-oll-rit-sameinud.pdf"; | ||
let pdfLink = ""; | ||
|
||
// Determine the PDF link based on the depth attribute | ||
if (depth === 0) { | ||
pdfLink = `./RUBIK-oll-rit-sameinud.pdf`; | ||
} else { | ||
// If the path has more than one part, the first part is the subfolder | ||
pdfLink = parts[0] + "/RUBIK-" + parts[0] + ".pdf"; | ||
let relativePath = "./"; | ||
|
||
// Generate the relative path prefix (../ for each depth level beyond 1) | ||
for (let i = 1; i < depth; i++) { | ||
relativePath += "../"; | ||
} | ||
|
||
pdfLink = `${relativePath}RUBIK-${subfolder}.pdf`; | ||
} | ||
|
||
// Set the href attribute of the PDF link | ||
document.getElementById("pdf-link").href = pdfLink; | ||
|
||
linkElement.href = pdfLink; | ||
}); | ||
</script> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters