-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_circular_nav.ps1
More file actions
61 lines (52 loc) · 2.41 KB
/
update_circular_nav.ps1
File metadata and controls
61 lines (52 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$root = "c:\Users\ablma\Documents\Cerezo\Web\condadodecastilla"
$alfozDir = Join-Path $root "lugares\alfozcerezolantaron"
# Get all town directories
$townDirs = Get-ChildItem -Path $alfozDir -Directory | Sort-Object Name
$towns = @()
foreach ($dir in $townDirs) {
$indexFile = Join-Path $dir.FullName "index.html"
if (Test-Path $indexFile) {
# Extract town name from title or folder name
$content = Get-Content $indexFile -Raw
$townName = $dir.Name -replace "_", " "
if ($content -match '<title>(.*?) -') {
$townName = $matches[1]
}
$towns += [PSCustomObject]@{
Name = $townName
DirName = $dir.Name
Path = $indexFile
}
}
}
$count = $towns.Count
for ($i = 0; $i -lt $count; $i++) {
$current = $towns[$i]
$prev = $towns[($i - 1 + $count) % $count]
$next = $towns[($i + 1) % $count]
$navHtml = @"
<div class="town-navigation" style="display: flex; justify-content: space-between; align-items: center; margin-top: 2em; flex-wrap: wrap; gap: 1em;">
<a href="../$($prev.DirName)/index.html" class="cta-button prev-town" title="Ir a $($prev.Name)">← $($prev.Name)</a>
<a href="../../../alfoz/alfoz.html" class="cta-button">Volver al Alfoz</a>
<a href="../$($next.DirName)/index.html" class="cta-button next-town" title="Ir a $($next.Name)">$($next.Name) →</a>
</div>
"@
$content = Get-Content $current.Path -Raw
# Regex to find the existing navigation or the "Volver al Alfoz" button container
# We look for the specific div structure we saw earlier
$pattern = '(?s)<div style="text-align: center; margin-top: 2em;">\s*<a href=".*?alfoz\.html".*?>.*?</a>\s*</div>'
if ($content -match $pattern) {
$content = $content -replace $pattern, $navHtml
Set-Content -Path $current.Path -Value $content
Write-Host "Updated navigation for $($current.Name)"
}
elseif ($content -match '<div class="town-navigation".*?</div>') {
# Already has nav, update it
$content = $content -replace '(?s)<div class="town-navigation".*?</div>', $navHtml
Set-Content -Path $current.Path -Value $content
Write-Host "Refreshed navigation for $($current.Name)"
}
else {
Write-Warning "Could not find navigation placeholder in $($current.Name)"
}
}