Skip to content

Commit 8c1778a

Browse files
committed
Add opt-in dynamic-publish-box (client-side current-version + page-versions)
When publish-setup.json website.dynamic-publish-box=true, the publish box emits version-agnostic placeholders for the 'current version' reference and the 'Page versions:' list, filled in client-side at page load from package-list.json (same origin; already the source of truth). The emitted markup is then identical on every page of every version regardless of which version is current, so cutting a new milestone no longer rewrites the publish box in past versions. - PublishBoxStatementGenerator: version-agnostic placeholder + one inline script that fills the current version/link, toggles superseded/is-current/pre-release wording, and builds the Page-versions list (HEAD-probing each milestone for the page). - IGReleaseVersionUpdater: addPageVersions emits the placeholder when enabled. - PublicationProcess / IGReleaseUpdater / IGWebSiteMaintainer: thread the flag through -go-publish and -publish-update at every call site. Off by default.
1 parent ad36e74 commit 8c1778a

5 files changed

Lines changed: 123 additions & 16 deletions

File tree

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/web/IGReleaseUpdater.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,20 @@ public static ServerType fromCode(String st) {
9292
private File sft;
9393
private boolean fullUpdate;
9494
private String historySource;
95+
private boolean dynamicPublishBox;
9596

9697
public IGReleaseUpdater(String folder, String url, String rootFolder, IGRegistryMaintainer reg, ServerType serverType, List<String> otherSpecs, File sft, boolean full, String historySource) throws IOException {
98+
this(folder, url, rootFolder, reg, serverType, otherSpecs, sft, full, historySource, false);
99+
}
100+
101+
public IGReleaseUpdater(String folder, String url, String rootFolder, IGRegistryMaintainer reg, ServerType serverType, List<String> otherSpecs, File sft, boolean full, String historySource, boolean dynamicPublishBox) throws IOException {
97102
this.folder = folder;
98103
this.url = url;
99104
this.rootFolder = rootFolder;
100105
this.fullUpdate = full;
101106
this.sft = sft;
102107
this.historySource = historySource;
108+
this.dynamicPublishBox = dynamicPublishBox;
103109
if (!"".equals("http://hl7.org/fhir")) { // keep the main spec out of the registry
104110
this.reg = reg;
105111
}
@@ -329,11 +335,11 @@ private boolean updateStatement(String vf, List<String> ignoreList, List<String>
329335
return false;
330336
}
331337
boolean vc = false;
332-
IGReleaseVersionUpdater igvu = new IGReleaseVersionUpdater(vf, url, rootFolder, ignoreList, ignoreListOuter, version, folder);
338+
IGReleaseVersionUpdater igvu = new IGReleaseVersionUpdater(vf, url, rootFolder, ignoreList, ignoreListOuter, version, folder, dynamicPublishBox);
333339
if (updateStatements) {
334340
PackageList pl = new PackageList(ig);
335341
PackageListEntry pv = pl.findByVersion(version.asString("version"));
336-
String fragment = PublishBoxStatementGenerator.genFragment(pl, pv, pl.current(), canonical, pv == pl.current(), false);
342+
String fragment = PublishBoxStatementGenerator.genFragment(pl, pv, pl.current(), canonical, pv == pl.current(), false, dynamicPublishBox);
337343
System.out.println(" "+vf+": "+fragment);
338344
igvu.updateStatement(fragment, ignoreList != null ? 0 : 1, milestones);
339345
System.out.println(" .. "+igvu.getCountTotal()+" files checked, "+igvu.getCountUpdated()+" updated");

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/web/IGReleaseVersionUpdater.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ public class IGReleaseVersionUpdater {
5858
private int clonedTotal;
5959
private String rootUrl;
6060
private String rootFolder;
61+
private boolean dynamicPublishBox;
6162

6263

6364
public IGReleaseVersionUpdater(String folder, String rootUrl, String rootFolder, List<String> ignoreList, List<String> ignoreListOuter, JsonObject version, String currentFolder) {
65+
this(folder, rootUrl, rootFolder, ignoreList, ignoreListOuter, version, currentFolder, false);
66+
}
67+
68+
public IGReleaseVersionUpdater(String folder, String rootUrl, String rootFolder, List<String> ignoreList, List<String> ignoreListOuter, JsonObject version, String currentFolder, boolean dynamicPublishBox) {
6469
this.folder = folder;
6570
this.ignoreList = ignoreList;
6671
this.ignoreListOuter = ignoreListOuter;
6772
this.version = version;
6873
this.currentFolder = currentFolder;
6974
this.rootFolder = rootFolder;
7075
this.rootUrl = rootUrl;
76+
this.dynamicPublishBox = dynamicPublishBox;
7177
}
7278

7379
public void updateStatement(String fragment, int level, List<PackageListEntry> milestones) throws FileNotFoundException, IOException {
@@ -160,7 +166,13 @@ private String addPageVersions(File f, List<PackageListEntry> milestones) throws
160166
if (milestones == null) {
161167
return "";
162168
}
163-
String relpath = FileUtilities.getRelativePath(folder, f.getAbsolutePath());
169+
if (dynamicPublishBox) {
170+
// version-agnostic placeholder: the "Page versions: ..." list is resolved client-side from
171+
// package-list.json (see PublishBoxStatementGenerator's script), so adding a new milestone
172+
// folder no longer rewrites this line in every past version's pages.
173+
return "<span class=\"fhir-pb-page-versions\" data-pb-version=\""+Utilities.escapeXml(version.asString("version"))+"\"></span>";
174+
}
175+
String relpath = FileUtilities.getRelativePath(folder, f.getAbsolutePath());
164176
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(" ");
165177
int i = 0;
166178
for (PackageListEntry t : milestones) {

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/web/IGWebSiteMaintainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static void execute(String folder, IGRegistryMaintainer reg, boolean doCo
7171
if (reg == null && !pubSetup.forceObject("website").asBoolean("no-registry"))
7272
throw new Error("This web site contains IGs that are registered in the implementation guide registry, and you must pass in a reference to the registry");
7373
ServerType serverType = ServerType.fromCode(pubSetup.forceObject("website").asString("server"));
74+
boolean dynamicPublishBox = pubSetup.forceObject("website").asBoolean("dynamic-publish-box");
7475

7576
File sft = null;
7677
if (pubSetup.forceObject("website").has("search-template")) {
@@ -110,7 +111,7 @@ public static void execute(String folder, IGRegistryMaintainer reg, boolean doCo
110111
}
111112
}
112113
for (String s : igs) {
113-
new IGReleaseUpdater(s, url, folder, reg, serverType, igs, sft, filter == null || filter.equalsIgnoreCase(s), historyRepo).check(indexes, true, updateStatements, templateSrc, "??");
114+
new IGReleaseUpdater(s, url, folder, reg, serverType, igs, sft, filter == null || filter.equalsIgnoreCase(s), historyRepo, dynamicPublishBox).check(indexes, true, updateStatements, templateSrc, "??");
114115
}
115116
for (IndexMaintainer index : indexes.values()) {
116117
index.buildJson();

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/web/PublicationProcess.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ private void doPublish(File fSource, File fOutput, JsonObject qa, String destina
597597
Date genDate, String username, String version, String gitSrcId, String tcName, String tcPath, PackageListEntry tcVer, String workingRoot, boolean jsonXmlClones, File igBuildZipDir, File previousPackageFile, String[] args, String replaces) throws Exception {
598598
// ok. all our tests have passed.
599599
// 1. do the publication build(s)
600+
boolean dynamicPublishBox = pubSetup.getJsonObject("website").asBoolean("dynamic-publish-box");
600601
List<String> existingFiles = new ArrayList<>();
601602
if (mode == PublicationProcessMode.CREATION) {
602603
System.out.println("All checks passed. Create an empty history at "+destination);
@@ -646,7 +647,7 @@ private void doPublish(File fSource, File fOutput, JsonObject qa, String destina
646647
System.out.println("Update "+Utilities.path(destination, "package-list.json"));
647648
PackageListEntry plVer = updatePackageList(pl, fSource.getAbsolutePath(), prSrc, pathVer, Utilities.path(destination, "package-list.json"), mode, date,
648649
npm.fhirVersion(), Utilities.pathURL(pubSetup.asString("url"), tcName), subPackages, prSrc.asString("previouslyPublishedAs"));
649-
updatePublishBox(pl, plVer, destVer, pathVer, destination, fRoot.getAbsolutePath(), false, ServerType.fromCode(pubSetup.getJsonObject("website").asString("server")), sft, null, url, jsonXmlClones);
650+
updatePublishBox(pl, plVer, destVer, pathVer, destination, fRoot.getAbsolutePath(), false, ServerType.fromCode(pubSetup.getJsonObject("website").asString("server")), sft, null, url, jsonXmlClones, dynamicPublishBox);
650651

651652
if (mode != PublicationProcessMode.WORKING || prSrc.has("movedFrom")) {
652653
String igSrc = tempM == null ? null : Utilities.path(tempM.getAbsolutePath(), "output");
@@ -676,7 +677,7 @@ private void doPublish(File fSource, File fOutput, JsonObject qa, String destina
676677
String vCode = pv.substring(pv.lastIndexOf("/")+1);
677678
String dv = Utilities.path(fRoot, relPath);
678679
System.out.println("Update publish box for version "+v.version()+" @ "+v.path());
679-
updatePublishBox(pl, v, dv, pv, destination, fRoot.getAbsolutePath(), false, null, null, null, url, jsonXmlClones);
680+
updatePublishBox(pl, v, dv, pv, destination, fRoot.getAbsolutePath(), false, null, null, null, url, jsonXmlClones, dynamicPublishBox);
680681
}
681682
}
682683
}
@@ -698,11 +699,11 @@ private void doPublish(File fSource, File fOutput, JsonObject qa, String destina
698699
}
699700
String vCode = tcPath.substring(tcPath.lastIndexOf("/")+1);
700701
String dv = Utilities.path(destination, vCode);
701-
updatePublishBox(pl, tcVer, dv, tcPath, destination, fRoot.getAbsolutePath(), false, null, null, null, url, jsonXmlClones);
702+
updatePublishBox(pl, tcVer, dv, tcPath, destination, fRoot.getAbsolutePath(), false, null, null, null, url, jsonXmlClones, dynamicPublishBox);
702703
}
703704
// we do this first in the output so we can get a proper diff
704705
if (igSrc != null) {
705-
updatePublishBox(pl, plVer, igSrc, pathVer, igSrc, fRoot.getAbsolutePath(), true, ServerType.fromCode(pubSetup.getJsonObject("website").asString("server")), sft, null, url, jsonXmlClones);
706+
updatePublishBox(pl, plVer, igSrc, pathVer, igSrc, fRoot.getAbsolutePath(), true, ServerType.fromCode(pubSetup.getJsonObject("website").asString("server")), sft, null, url, jsonXmlClones, dynamicPublishBox);
706707

707708
System.out.println("Check for Files to delete");
708709
List<String> newFiles = igSrc == null ? new ArrayList<>() : FileUtilities.listAllFiles(igSrc, null);
@@ -730,7 +731,7 @@ private void doPublish(File fSource, File fOutput, JsonObject qa, String destina
730731
ignoreList.add(Utilities.path(dpath, v.path().substring(path.length()+1)));
731732
}
732733
}
733-
updatePublishBox(pl, pl.current(), dpath, path, dpath, fRoot.getAbsolutePath(), true, null, null, ignoreList, url, jsonXmlClones);
734+
updatePublishBox(pl, pl.current(), dpath, path, dpath, fRoot.getAbsolutePath(), true, null, null, ignoreList, url, jsonXmlClones, dynamicPublishBox);
734735
}
735736
} else {
736737
src.cleanFolder(relDest);
@@ -1044,9 +1045,9 @@ public String presentDate(Date date) {
10441045
return sdf.format(date);
10451046
}
10461047

1047-
private void updatePublishBox(PackageList pl, PackageListEntry plVer, String destVer, String pathVer, String destination, String rootFolder, boolean current, ServerType serverType, File sft, List<String> ignoreList, String url, boolean jsonXmlClones) throws FileNotFoundException, IOException {
1048-
IGReleaseVersionUpdater igvu = new IGReleaseVersionUpdater(destVer, url, rootFolder, ignoreList, null, plVer.json(), destination);
1049-
String fragment = PublishBoxStatementGenerator.genFragment(pl, plVer, pl.current(), pl.canonical(), current, false);
1048+
private void updatePublishBox(PackageList pl, PackageListEntry plVer, String destVer, String pathVer, String destination, String rootFolder, boolean current, ServerType serverType, File sft, List<String> ignoreList, String url, boolean jsonXmlClones, boolean dynamicPublishBox) throws FileNotFoundException, IOException {
1049+
IGReleaseVersionUpdater igvu = new IGReleaseVersionUpdater(destVer, url, rootFolder, ignoreList, null, plVer.json(), destination, dynamicPublishBox);
1050+
String fragment = PublishBoxStatementGenerator.genFragment(pl, plVer, pl.current(), pl.canonical(), current, false, dynamicPublishBox);
10501051
System.out.println("Publish Box Statement: "+fragment);
10511052
igvu.updateStatement(fragment, current ? 0 : 1, pl.milestones());
10521053
System.out.println(" .. "+igvu.getCountTotal()+" files checked, "+igvu.getCountUpdated()+" updated");
@@ -1343,7 +1344,7 @@ private List<ValidationMessage> processWithdrawal(String source, String web, Str
13431344
String vCode = pv.substring(pv.lastIndexOf("/")+1);
13441345
String dv = Utilities.path(destination, vCode);
13451346
System.out.println("Update publish box for version "+v.version()+" @ "+v.path());
1346-
updatePublishBox(pl, v, dv, pv, destination, fRoot.getAbsolutePath(), false, null, null, null, url, false);
1347+
updatePublishBox(pl, v, dv, pv, destination, fRoot.getAbsolutePath(), false, null, null, null, url, false, pubSetup.getJsonObject("website").asBoolean("dynamic-publish-box"));
13471348
}
13481349
}
13491350

0 commit comments

Comments
 (0)