Skip to content

Commit 91479c7

Browse files
authored
Merge pull request #421 from VirtualFlyBrain/fix/legacy-shortcodes-and-prune
Stop superseded term pages from aborting the build
2 parents a5f632b + ff816c0 commit 91479c7

4 files changed

Lines changed: 98 additions & 7 deletions

File tree

‎themes/vfb-nova/assets/css/compat.css‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,35 @@
106106
background: var(--surface);
107107
translate: 0 -.15em;
108108
}
109+
110+
/* --------------------------------------------------------------------------
111+
Bootstrap `alert`, for the legacy Docsy shortcodes reimplemented in
112+
layouts/shortcodes/{alert,pageinfo}.html. Superseded term pages call them,
113+
and without a template the whole build fails; without these rules they
114+
would render as unstyled text. Uses the theme's own tokens rather than
115+
Bootstrap's palette so they sit with the rest of the page.
116+
-------------------------------------------------------------------------- */
117+
.prose .alert {
118+
display: block;
119+
padding: var(--sp-4) var(--sp-5);
120+
margin: var(--sp-5) 0;
121+
border: 1px solid var(--line);
122+
border-left-width: 3px;
123+
border-radius: var(--r-md);
124+
background: var(--elev-1);
125+
}
126+
.prose .alert > :first-child { margin-top: 0; }
127+
.prose .alert > :last-child { margin-bottom: 0; }
128+
.prose .alert-heading {
129+
margin: 0 0 var(--sp-2);
130+
font-size: 1rem;
131+
font-weight: 600;
132+
}
133+
.prose .alert-primary,
134+
.prose .alert-info { border-left-color: rgba(76, 141, 255, .7); }
135+
.prose .alert-success { border-left-color: rgba(64, 192, 128, .7); }
136+
.prose .alert-warning { border-left-color: rgba(230, 168, 64, .7); }
137+
.prose .alert-danger { border-left-color: rgba(230, 96, 96, .7); }
138+
.prose .alert-secondary,
139+
.prose .alert-light,
140+
.prose .alert-dark { border-left-color: var(--line); }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{/*
2+
Docsy's `alert`, reimplemented so legacy generated pages still render.
3+
4+
Term pages written by vfbterms.py version 6 and earlier used Docsy
5+
shortcodes. Those files are superseded but survive in the corpus whenever a
6+
term drops out of one run's ID list, and a single one aborts the entire
7+
build — twice now, at 93 and 38 minutes a time. The cost of shipping this is
8+
one small template; the cost of not shipping it is a lost build per orphan.
9+
10+
Same signature as Docsy: {{< alert title="..." color="..." >}} ... {{< /alert >}}
11+
`.Inner | markdownify` matches Docsy's own implementation, so pages written
12+
against it render as they did.
13+
*/}}
14+
{{- $color := .Get "color" | default "primary" -}}
15+
<div class="alert alert-{{ $color }}" role="alert">
16+
{{- with .Get "title" }}<h4 class="alert-heading">{{ . }}</h4>{{ end }}
17+
{{ .Inner | markdownify }}
18+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{/*
2+
Docsy's `pageinfo`, for the same reason as alert.html: legacy generated pages
3+
call it, and a missing shortcode template is a hard build error rather than a
4+
warning. Shipped pre-emptively so the next orphan does not cost another build.
5+
*/}}
6+
{{- $color := .Get "color" | default "info" -}}
7+
<div class="pageinfo pageinfo-{{ $color }} alert alert-{{ $color }}" role="note">
8+
{{ .Inner | markdownify }}
9+
</div>

‎vfbterms.py‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,51 @@ def fetch_ids(label, query):
757757
print(f" Retrieved {len(ids)} IDs for {label}")
758758
return ids
759759

760+
_VERSION_SUFFIX = re.compile(r"_v(\d+)\.md$")
761+
762+
763+
def prune_old_versions(label):
764+
"""Delete superseded term pages in the current directory.
765+
766+
process_term() used to remove only version-1 after writing a page. A term
767+
absent from a single run's ID list therefore kept its older file forever:
768+
the corpus still held _v6 pages long after version reached 9. Those orphans
769+
are live pages -- they can collide on URL with the current version, they
770+
are walked and parsed on every build, and pages old enough to predate the
771+
move off Docsy call shortcodes the theme no longer ships, which aborts the
772+
whole build.
773+
774+
One directory scan rather than a stat per term per version. The per-term
775+
form costs version-1 extra syscalls for every term, which at ~763k terms is
776+
millions of round trips; on the NFS volume this corpus lives on, metadata
777+
operations run at a few hundred per second, so that is hours. This also
778+
removes one stat per term relative to the old code.
779+
"""
780+
removed = 0
781+
try:
782+
with os.scandir(".") as entries:
783+
for entry in entries:
784+
match = _VERSION_SUFFIX.search(entry.name)
785+
if match and int(match.group(1)) < version:
786+
try:
787+
os.remove(entry.name)
788+
removed += 1
789+
except OSError:
790+
pass
791+
except OSError as e:
792+
print(f"WARNING: could not prune {label}: {e}")
793+
return
794+
if removed:
795+
print(f" pruned {removed} superseded pages from {label}")
796+
797+
760798
def process_group(base_path, relative_dir, label, query):
761799
"""Change directory, fetch IDs, and generate pages for one ontology group."""
762800
target_dir = os.path.normpath(join(base_path, relative_dir))
763801
print(f"\n[{label}] {target_dir}")
764802
chdir(target_dir)
765803
save_terms(fetch_ids(label, query))
804+
prune_old_versions(label)
766805

767806
def process_term(term_id):
768807
"""Fetch, render and write one term page. Returns a status string.
@@ -786,13 +825,6 @@ def process_term(term_id):
786825
f.write(page_content)
787826
os.replace(tmp, filename)
788827

789-
# Clean up previous version
790-
old_filename = term_id + "_v" + str(version - 1) + ".md"
791-
if os.path.isfile(old_filename):
792-
try:
793-
os.remove(old_filename)
794-
except OSError:
795-
pass
796828
return "ok"
797829

798830
def save_terms(ids):

0 commit comments

Comments
 (0)