Skip to content

Commit

Permalink
Readme will now contain table of content
Browse files Browse the repository at this point in the history
  • Loading branch information
on committed Oct 1, 2025
1 parent b348aa8 commit 68ee1c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions ReadmeTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TamperMonkey scripts to improve sites (Fuglane, Innsida etc.)
4. TamperMonkey should open and ask you to install the script

# Scripts
{content_list}
{scriptlist}

# Contribute
Expand Down
45 changes: 41 additions & 4 deletions generate-readme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,45 @@ $UserScripts = "."
#$userJsFiles = Get-ChildItem -Path $UserScripts -Filter "*.user.js" | Sort-Object Name
$userJsFiles = Get-ChildItem -Path $UserScripts -Filter "*.user.js" | Select-Object fullname, name, @{ Name = 'NameTag'; Expression = { $name_tag = ([regex]"@name\s+(.+)").Match((Get-Content $_.fullname -Raw)).Groups[1].value; if ($name_tag -eq "") { $_.name} else { $name_tag } }} | sort NameTag


$regEx = [regex]'\/\/\s+@(\w+)\s+(.+)'

$scriptList = @()
$content_list = "| Script | Author | Version |`n|--------|--------|---------|`n"
$scriptList = ""

function New-GfmHeaderLink {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string]$HeaderText
)

process {
# 1. Konverter til små bokstaver
$slug = $HeaderText.ToLower()

# 2. Erstatt spesialtegn (alt som ikke er bokstaver, tall eller mellomrom) med et bindestrek
# Dette fjerner også aksenter fra norske bokstaver og andre spesialtegn.
# Vi beholder 'æøå' og erstatter dem i neste steg for å få standard GFM-oppførsel.
$slug = $slug -replace '[^a-z0-9\sæøå-]', ''

# Spesifikk erstatning for norske tegn for å følge vanlig praksis i engelske systemer
# (selv om GFM støtter dem, konverteres de ofte for bredere kompatibilitet)
$slug = $slug -replace 'æ', 'ae'
$slug = $slug -replace 'ø', 'o'
$slug = $slug -replace 'å', 'a'

# 3. Erstatt mellomrom med bindestreker
$slug = $slug -replace '\s+', '-'

# 4. Kollaps flere bindestreker til én og fjern ledende/etterfølgende bindestreker
$slug = $slug -replace '-{2,}', '-'
$slug = $slug.Trim('-')

# Returner den komplette Markdown-lenken
Write-Output "[$HeaderText](#$slug)"
}
}


# Loop through each file
foreach ($file in $userJsFiles) {
Expand Down Expand Up @@ -66,8 +101,9 @@ foreach ($file in $userJsFiles) {
} while (($i -lt $content.Length) -and (-not $endOfCommentBlock))

$endOfCommentBlock = $false

$scriptList += " ### $name`n`n"
$script_heading = " ### $name"
$content_list += "| " + (New-GfmHeaderLink -HeaderText $name) + " | $author | $version |" + "`n"
$scriptList += "$script_heading`n`n"
$scriptList += " - **Install:** "
if ($autoUpdate) { $color = "green" } else { $color = "blue" }
$scriptList += New-MDImage -Subject "$($file.Name)" -Status "$version" -Color $color -Link "https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/$($file.Name)"
Expand Down Expand Up @@ -112,4 +148,5 @@ foreach ($file in $userJsFiles) {
}

$template = Get-Content .\ReadmeTemplate.md
$template = $template -replace '{content_list}', $content_list
$template -replace '{scriptlist}', $scriptList

0 comments on commit 68ee1c6

Please sign in to comment.