Skip to content

Commit 72caffc

Browse files
authored
Merge branch 'MilesCranmer:abstract-popmember' into abstract-popmember
2 parents 30bd293 + 000ed94 commit 72caffc

File tree

5 files changed

+101
-4
lines changed

5 files changed

+101
-4
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: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ function fix_vitepress_base_path()
190190
"/SymbolicRegression.jl/dev/"
191191
end
192192

193+
# The version picker should link to sibling versions that live one
194+
# directory above the active version, e.g. `/symbolicregression/v1.12.0/`.
195+
# Compute that shared prefix (always the first path segment) so that we can
196+
# rewrite `__DEPLOY_ABSPATH__` accordingly.
197+
stripped = isempty(base_path) ? base_path : rstrip(base_path, '/')
198+
segments = split(stripped, '/'; keepempty=false)
199+
deploy_abspath = isempty(segments) ? "/" : "/" * first(segments) * "/"
200+
193201
# Find and fix VitePress SOURCE config file (before build)
194202
config_paths = [joinpath(@__DIR__, "src", ".vitepress", "config.mts")]
195203

@@ -201,18 +209,57 @@ function fix_vitepress_base_path()
201209
# Replace the base path with the correct one for this deployment
202210
# Look for existing base: '...' patterns and replace them
203211
content = replace(content, r"base:\s*'[^']*'" => "base: '$base_path'")
212+
content = replace(
213+
content,
214+
r"__DEPLOY_ABSPATH__\s*:\s*JSON\.stringify\('[^']*'\)" =>
215+
"__DEPLOY_ABSPATH__: JSON.stringify('$deploy_abspath')",
216+
)
204217

205218
write(config_path, content)
206-
@info "Updated VitePress base path to: $base_path"
219+
@info "Updated VitePress base path to: $base_path (deploy abspath: $deploy_abspath)"
207220
else
208221
@warn "VitePress config not found at: $config_path"
209222
end
210223
end
211224
end
212225

226+
# Generate favicon files from logo.png
227+
function generate_favicons()
228+
logo_path = joinpath(@__DIR__, "src", "assets", "logo.png")
229+
public_dir = joinpath(@__DIR__, "src", "public")
230+
231+
if !isfile(logo_path)
232+
@warn "Logo file not found at: $logo_path - skipping favicon generation"
233+
return false
234+
end
235+
236+
mkpath(public_dir)
237+
238+
@info "Generating favicon files from logo.png..."
239+
240+
# Generate different sizes
241+
favicon_configs = [
242+
("favicon.ico", "32x32"),
243+
("favicon-16x16.png", "16x16"),
244+
("favicon-32x32.png", "32x32"),
245+
("apple-touch-icon.png", "180x180"),
246+
]
247+
248+
for (filename, size) in favicon_configs
249+
output_path = joinpath(public_dir, filename)
250+
run(`magick $(logo_path) -resize $(size) -background none -gravity center -extent $(size) $(output_path)`)
251+
@info "Generated: $filename"
252+
end
253+
254+
return true
255+
end
256+
213257
# Run preprocessing on source files before makedocs()
214258
preprocess_source_index()
215259

260+
# Generate favicons before building docs
261+
generate_favicons()
262+
216263
# Fix VitePress base path BEFORE makedocs() - this is crucial for timing!
217264
fix_vitepress_base_path()
218265

@@ -240,6 +287,20 @@ else
240287
)
241288
end
242289

290+
current_version = let
291+
version = get(ENV, "DOCUMENTER_VERSION", nothing)
292+
if version !== nothing && !isempty(version)
293+
version
294+
else
295+
fallback = get(ENV, "DOCUMENTER_CURRENT_VERSION", nothing)
296+
if fallback !== nothing && !isempty(fallback)
297+
fallback
298+
else
299+
"dev"
300+
end
301+
end
302+
end
303+
243304
DocMeta.setdocmeta!(
244305
SymbolicRegression,
245306
:DocTestSetup,
@@ -250,6 +311,7 @@ DocMeta.setdocmeta!(
250311
makedocs(;
251312
sitename="SymbolicRegression.jl",
252313
authors="Miles Cranmer",
314+
current_version=current_version,
253315
doctest=true,
254316
clean=get(ENV, "DOCUMENTER_PRODUCTION", "false") == "true",
255317
warnonly=[:docs_block, :cross_references, :missing_docs],
@@ -291,9 +353,19 @@ post_process_vitepress_index()
291353
function fix_empty_bases()
292354
bases_file = joinpath(@__DIR__, "build", "bases.txt")
293355
mkpath(dirname(bases_file))
294-
if !isfile(bases_file) || isempty(filter(!isempty, readlines(bases_file)))
295-
@info "Creating/fixing bases.txt for deployment"
356+
357+
if !isfile(bases_file)
358+
@info "Creating bases.txt for dev deployment"
296359
write(bases_file, "dev\n")
360+
else
361+
bases = filter(!isempty, readlines(bases_file))
362+
if isempty(bases)
363+
@info "Fixing empty bases.txt for dev deployment"
364+
write(bases_file, "dev\n")
365+
else
366+
@info "bases.txt already exists with $(length(bases)) bases: $bases"
367+
# Don't overwrite it - DocumenterVitepress may have generated multiple bases
368+
end
297369
end
298370
end
299371

docs/src/.vitepress/config.mts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const navTemp = {
1919

2020
const nav = [
2121
...navTemp.nav,
22+
{
23+
text: 'Julia',
24+
items: [
25+
{ text: 'Julia', link: '/' },
26+
{ text: 'Python', link: 'https://ai.damtp.cam.ac.uk/pysr/dev/' }
27+
]
28+
},
2229
{
2330
component: 'VersionPicker'
2431
}
@@ -33,7 +40,11 @@ export default defineConfig({
3340
cleanUrls: true,
3441
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
3542
head: [
36-
['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` }],
47+
['link', { rel: 'stylesheet', href: `${baseTemp.base}nav-logo.css` }],
3748
['script', {src: `${getBaseRepository(baseTemp.base)}versions.js`}],
3849
// ['script', {src: '/versions.js'], for custom domains, I guess if deploy_url is available.
3950
['script', {src: `${baseTemp.base}siteinfo.js`}]

docs/src/.vitepress/theme/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,11 @@ html.dark {
9090
border-top: 1px solid var(--vp-c-divider);
9191
padding-top: 48px;
9292
}
93+
94+
/* Make language picker match version picker styling (black text, not colored) */
95+
.VPNavBarMenuGroup button .text {
96+
color: var(--vp-c-text-1) !important;
97+
}
98+
.VPNavBarMenuGroup:hover button .text {
99+
color: var(--vp-c-text-2) !important;
100+
}

docs/src/public/nav-logo.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.VPNavBarTitle .VPImage.logo {
2+
height: 24px;
3+
width: auto;
4+
}

0 commit comments

Comments
 (0)