Skip to content

Commit 5d32111

Browse files
committed
Open-sourcing my work
1 parent 6d8920b commit 5d32111

9 files changed

Lines changed: 862 additions & 0 deletions

File tree

.github/workflows/fetch-icons.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Fetch missing Silk icons
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- '404.html'
8+
- '_layouts/directory.html'
9+
- '_includes/icon_mapper.html'
10+
- '.github/workflows/fetch-icons.yml'
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
fetch-icons:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Fetch missing icons (PowerShell)
26+
shell: pwsh
27+
run: |
28+
$404File = '404.html'
29+
$LayoutFile = '_layouts/directory.html'
30+
$MapperFile = '_includes/icon_mapper.html'
31+
32+
$combinedContent = ""
33+
34+
if (Test-Path $404File) {
35+
Write-Host "Reading 404 page..."
36+
$combinedContent += Get-Content $404File -Raw
37+
}
38+
39+
if (Test-Path $LayoutFile) {
40+
Write-Host "Reading directory layout..."
41+
$combinedContent += Get-Content $LayoutFile -Raw
42+
}
43+
44+
if (Test-Path $MapperFile) {
45+
Write-Host "Reading icon mapper component..."
46+
$combinedContent += Get-Content $MapperFile -Raw
47+
}
48+
49+
if ($combinedContent -eq "") {
50+
Write-Host "No 404 page, layout or mapper files found, skipping icon fetch."
51+
exit 0
52+
}
53+
54+
$pattern = "(?<=assign icon = ')[^']+(?=')|(?<=src=""/assets/icons/)[^/]+(?=\.png"")"
55+
$icons = [regex]::Matches($combinedContent, $pattern) | ForEach-Object { $_.Value } | Sort-Object -Unique
56+
57+
Write-Host "Icons referenced in architecture: $($icons -join ', ')"
58+
59+
$iconDir = 'assets/icons'
60+
New-Item -ItemType Directory -Force -Path $iconDir | Out-Null
61+
62+
$placeholderName = '__placeholder'
63+
$placeholderFile = "$iconDir/$placeholderName.png"
64+
$placeholderUrl = 'https://upload.wikimedia.org/wikipedia/commons/8/8c/Transparent.png'
65+
66+
$changedFiles = @()
67+
$fallbackIcons = @()
68+
69+
if (-not (Test-Path $placeholderFile)) {
70+
Write-Host "Downloading placeholder icon from $placeholderUrl ..."
71+
Invoke-WebRequest -Uri $placeholderUrl -OutFile $placeholderFile -ErrorAction Stop
72+
$changedFiles += $placeholderFile
73+
}
74+
75+
foreach ($icon in $icons) {
76+
if ($icon -eq $placeholderName) {
77+
continue
78+
}
79+
80+
if ($icon -eq "{{ icon }}" -or $icon -eq "{{ icon_name }}") {
81+
continue
82+
}
83+
84+
$iconFile = "$iconDir/$icon.png"
85+
$item = Get-Item -LiteralPath $iconFile -ErrorAction SilentlyContinue
86+
$isLink = $null -ne $item -and $null -ne $item.LinkType
87+
$needsDownload = ($null -eq $item) -or $isLink
88+
89+
if ($needsDownload) {
90+
$url = "https://raw.githubusercontent.com/markjames/famfamfam-silk-icons/master/icons/$icon.png"
91+
$tempFile = "$iconFile.download"
92+
Write-Host "Downloading $icon.png from $url ..."
93+
try {
94+
Invoke-WebRequest -Uri $url -OutFile $tempFile -ErrorAction Stop
95+
if (Test-Path $iconFile) { Remove-Item -LiteralPath $iconFile -Force }
96+
Move-Item -LiteralPath $tempFile -Destination $iconFile -Force
97+
$changedFiles += $iconFile
98+
Write-Host " -> saved"
99+
} catch {
100+
if (Test-Path $tempFile) { Remove-Item -LiteralPath $tempFile -Force }
101+
Write-Warning "Failed to download $icon.png : $_"
102+
if (Test-Path $iconFile) { Remove-Item -LiteralPath $iconFile -Force }
103+
try {
104+
New-Item -ItemType SymbolicLink -Path $iconFile -Target "$placeholderName.png" -Force | Out-Null
105+
Write-Host " -> linked to placeholder"
106+
} catch {
107+
Copy-Item -LiteralPath $placeholderFile -Destination $iconFile -Force
108+
Write-Host " -> copied placeholder"
109+
}
110+
$changedFiles += $iconFile
111+
$fallbackIcons += "$icon.png"
112+
}
113+
} else {
114+
Write-Host "$icon.png already exists, skipping."
115+
}
116+
}
117+
118+
if ($fallbackIcons.Count -gt 0) {
119+
Write-Warning "Using placeholder for: $($fallbackIcons -join ', ')"
120+
}
121+
122+
if ($changedFiles.Count -gt 0) {
123+
Write-Host "Committing icon file updates..."
124+
git config user.name "github-actions[bot]"
125+
git config user.email "github-actions[bot]@users.noreply.github.com"
126+
git add assets/icons/
127+
git commit -m "Update directory listing icons [skip ci]"
128+
git push
129+
} else {
130+
Write-Host "All icons already present, nothing to commit."
131+
}

.github/workflows/pages.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy Jekyll site to Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- '404.html'
8+
- '_layouts/directory.html'
9+
- '_includes/icon_mapper.html'
10+
- '.github/workflows/fetch-icons.yml'
11+
workflow_run:
12+
workflows: [ "Fetch missing Silk icons" ]
13+
types:
14+
- completed
15+
workflow_dispatch:
16+
17+
permissions:
18+
contents: read
19+
pages: write
20+
id-token: write
21+
22+
concurrency:
23+
group: "pages"
24+
cancel-in-progress: true
25+
26+
jobs:
27+
build:
28+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout source
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.repository.default_branch }}
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: '20'
40+
41+
- name: Generate directory listing data & pages
42+
run: node generate-directory-listings.js
43+
44+
- name: Setup Pages
45+
uses: actions/configure-pages@v4
46+
47+
- name: Build with Jekyll
48+
uses: actions/jekyll-build-pages@v1
49+
with:
50+
source: ./
51+
destination: ./_site
52+
53+
- name: Upload artifact
54+
uses: actions/upload-pages-artifact@v3
55+
with:
56+
path: ./_site
57+
58+
deploy:
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
runs-on: ubuntu-latest
63+
needs: build
64+
steps:
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4

_includes/icon_mapper.html

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{% assign ext = include.ext %}
2+
{% assign icon = 'page_white' %}
3+
4+
{% case ext %}
5+
{% comment %} --- Documents & Text --- {% endcomment %}
6+
{% when 'txt','md','log','nfo','err' %}
7+
{% assign icon = 'page_white_text' %}
8+
{% when 'pdf' %}
9+
{% assign icon = 'page_white_acrobat' %}
10+
{% when 'doc','docx','rtf','odt' %}
11+
{% assign icon = 'page_white_word' %}
12+
{% when 'xls','xlsx','csv','ods','tsv' %}
13+
{% assign icon = 'page_white_excel' %}
14+
{% when 'ppt','pptx','pps','odp' %}
15+
{% assign icon = 'page_white_powerpoint' %}
16+
{% when 'epub','mobi','azw','cbz','cbr' %}
17+
{% assign icon = 'book' %}
18+
19+
{% comment %} --- Images & Design --- {% endcomment %}
20+
{% when 'jpg','jpeg','png','gif','bmp','webp','ico','tiff','tif' %}
21+
{% assign icon = 'page_white_picture' %}
22+
{% when 'svg','eps','ai','cdr' %}
23+
{% assign icon = 'page_white_vector' %}
24+
{% when 'psd','xcf' %}
25+
{% assign icon = 'page_white_paint' %}
26+
{% when 'swf' %}
27+
{% assign icon = 'page_white_flash' %}
28+
29+
{% comment %} --- Web & Code --- {% endcomment %}
30+
{% when 'html','htm','shtml','xhtml' %}
31+
{% assign icon = 'page_white_code' %}
32+
{% when 'css','less','sass','scss' %}
33+
{% assign icon = 'page_white_code' %}
34+
{% when 'js','ts','jsx','tsx','json','xml','yaml','yml' %}
35+
{% assign icon = 'page_white_code' %}
36+
{% when 'php','phtml' %}
37+
{% assign icon = 'page_white_php' %}
38+
{% when 'rb' %}
39+
{% assign icon = 'page_white_ruby' %}
40+
{% when 'c','h' %}
41+
{% assign icon = 'page_white_c' %}
42+
{% when 'cpp','cc','cxx','hpp' %}
43+
{% assign icon = 'page_white_cplusplus' %}
44+
{% when 'cs' %}
45+
{% assign icon = 'page_white_csharp' %}
46+
{% when 'java','class','jar' %}
47+
{% assign icon = 'page_white_cup' %}
48+
{% when 'sln','csproj','vbproj','vb' %}
49+
{% assign icon = 'page_white_visualstudio' %}
50+
{% when 'as' %}
51+
{% assign icon = 'page_white_actionscript' %}
52+
{% when 'cfm','cfc' %}
53+
{% assign icon = 'page_white_coldfusion' %}
54+
55+
{% comment %} --- System, Executables & Configs --- {% endcomment %}
56+
{% when 'exe','msi','bat','cmd','ps1','reg' %}
57+
{% assign icon = 'application_xp' %}
58+
{% when 'dmg','app','pkg','command' %}
59+
{% assign icon = 'application_osx' %}
60+
{% when 'sh','bash','zsh' %}
61+
{% assign icon = 'page_white_tux' %}
62+
{% when 'dll','sys','so','dylib','ini','conf','cfg','env' %}
63+
{% assign icon = 'page_white_gear' %}
64+
65+
{% comment %} --- Archives & Disk Images --- {% endcomment %}
66+
{% when 'zip' %}
67+
{% assign icon = 'page_white_zip' %}
68+
{% when 'tar','gz','rar','7z','bz2','xz' %}
69+
{% assign icon = 'page_white_compressed' %}
70+
{% when 'iso','img','vdi','vmdk','qcow2','cue','mds' %}
71+
{% assign icon = 'page_white_cd' %}
72+
{% when 'vob','ifo' %}
73+
{% assign icon = 'page_white_dvd' %}
74+
75+
{% comment %} --- Audio & Video --- {% endcomment %}
76+
{% when 'mp3','wav','flac','ogg','m4a','wma','aac','mid','midi' %}
77+
{% assign icon = 'music' %}
78+
{% when 'mp4','avi','mkv','mov','wmv','webm','m4v','flv' %}
79+
{% assign icon = 'film' %}
80+
81+
{% comment %} --- Databases --- {% endcomment %}
82+
{% when 'sql','db','sqlite','sqlite3','mdb','accdb','frm','ibd' %}
83+
{% assign icon = 'page_white_database' %}
84+
85+
{% comment %} --- Misc Useful Types --- {% endcomment %}
86+
{% when 'ttf','otf','woff','woff2','eot' %}
87+
{% assign icon = 'font' %}
88+
{% when 'vcf' %}
89+
{% assign icon = 'vcard' %}
90+
{% when 'ics' %}
91+
{% assign icon = 'calendar' %}
92+
{% when 'rss','atom' %}
93+
{% assign icon = 'feed' %}
94+
{% endcase %}
95+
{{- icon -}}

0 commit comments

Comments
 (0)