Skip to content

Commit ebae526

Browse files
authored
Merge pull request #513 from MilesCranmer/add-favicon-to-docs
docs: generate favicon from logo
2 parents 9aeb34c + 6f72331 commit ebae526

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.github/workflows/Documentation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
4949
- name: "Install Node.js dependencies"
5050
run: cd docs && npm install
51+
- name: "Install ImageMagick"
52+
run: sudo apt-get update && sudo apt-get install -y imagemagick
5153
- name: "Build and deploy"
5254
env:
5355
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docs/make.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,43 @@ function fix_vitepress_base_path()
210210
end
211211
end
212212

213+
# Generate favicon files from logo.png
214+
function generate_favicons()
215+
logo_path = joinpath(@__DIR__, "src", "assets", "logo.png")
216+
public_dir = joinpath(@__DIR__, "src", "public")
217+
218+
if !isfile(logo_path)
219+
@warn "Logo file not found at: $logo_path - skipping favicon generation"
220+
return false
221+
end
222+
223+
mkpath(public_dir)
224+
225+
@info "Generating favicon files from logo.png..."
226+
227+
# Generate different sizes
228+
favicon_configs = [
229+
("favicon.ico", "32x32"),
230+
("favicon-16x16.png", "16x16"),
231+
("favicon-32x32.png", "32x32"),
232+
("apple-touch-icon.png", "180x180"),
233+
]
234+
235+
for (filename, size) in favicon_configs
236+
output_path = joinpath(public_dir, filename)
237+
run(`magick $(logo_path) -resize $(size) -background none -gravity center -extent $(size) $(output_path)`)
238+
@info "Generated: $filename"
239+
end
240+
241+
return true
242+
end
243+
213244
# Run preprocessing on source files before makedocs()
214245
preprocess_source_index()
215246

247+
# Generate favicons before building docs
248+
generate_favicons()
249+
216250
# Fix VitePress base path BEFORE makedocs() - this is crucial for timing!
217251
fix_vitepress_base_path()
218252

docs/src/.vitepress/config.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export default defineConfig({
4040
cleanUrls: true,
4141
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
4242
head: [
43-
['link', { rel: 'icon', href: `${baseTemp.base}favicon.ico` }],
43+
['link', { rel: 'icon', type: 'image/x-icon', href: `${baseTemp.base}favicon.ico` }],
44+
['link', { rel: 'icon', type: 'image/png', sizes: '16x16', href: `${baseTemp.base}favicon-16x16.png` }],
45+
['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: `${baseTemp.base}favicon-32x32.png` }],
46+
['link', { rel: 'apple-touch-icon', sizes: '180x180', href: `${baseTemp.base}apple-touch-icon.png` }],
4447
['script', {src: `${getBaseRepository(baseTemp.base)}versions.js`}],
4548
// ['script', {src: '/versions.js'], for custom domains, I guess if deploy_url is available.
4649
['script', {src: `${baseTemp.base}siteinfo.js`}]

0 commit comments

Comments
 (0)