From 0b0c511c93ecdebd6ce38c2faa7149979987949b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 27 Oct 2023 16:02:39 +0200 Subject: [PATCH] Use the correct `/version/` instead of `/versions/` in guide HTTP paths For some reason quarkus.io in its source code uses `/_versions/`, but the generated site uses `/version/`... --- .../search/app/fetching/QuarkusIO.java | 23 ++++++++----------- .../quarkus/search/app/SearchServiceTest.java | 4 ++-- .../app/fetching/FetchingServiceTest.java | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java b/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java index a5a17fd1..c8a2b194 100644 --- a/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java +++ b/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java @@ -46,18 +46,24 @@ public Stream guides() throws IOException { @SuppressWarnings("resource") private Stream guideDirectories() throws IOException { return Stream.concat( - Stream.of(new GuidesDirectory(QuarkusVersions.LATEST, directory.path().resolve("_guides"))), + Stream.of(new GuidesDirectory(directory.path().resolve("_guides"), + QuarkusVersions.LATEST, "/guides/")), Files.list(directory.path().resolve("_versions")) - .map(p -> new GuidesDirectory(p.getFileName().toString(), p.resolve("guides")))); + .map(p -> { + var version = p.getFileName().toString(); + return new GuidesDirectory(p.resolve("guides"), version, + "/version/" + version + "/guides/"); + })); } - record GuidesDirectory(String version, Path path) { + record GuidesDirectory(Path path, String version, String htmlPathPrefix) { } private Guide parseGuide(GuidesDirectory guidesDirectory, Path path) { var guide = new Guide(); guide.version = guidesDirectory.version; - guide.relativePath = toHttpPath(directory.path().relativize(path).toString()); + guide.relativePath = guidesDirectory.htmlPathPrefix + + FilenameUtils.removeExtension(guidesDirectory.path.relativize(path).toString()); guide.fullContentPath = new PathWrapper(path); Asciidoc.parse(path, title -> guide.title = title, Map.of("summary", summary -> guide.summary = summary, @@ -68,15 +74,6 @@ private Guide parseGuide(GuidesDirectory guidesDirectory, Path path) { return guide; } - private String toHttpPath(String asciiDocPath) { - String result = FilenameUtils.removeExtension(asciiDocPath); - if (result.startsWith("_")) { - result = result.substring(1); - } - result = "/" + result; - return result; - } - private static Set toSet(String value) { if (value == null || value.isBlank()) { return Set.of(); diff --git a/src/test/java/io/quarkus/search/app/SearchServiceTest.java b/src/test/java/io/quarkus/search/app/SearchServiceTest.java index 2e711806..c6bf87a7 100644 --- a/src/test/java/io/quarkus/search/app/SearchServiceTest.java +++ b/src/test/java/io/quarkus/search/app/SearchServiceTest.java @@ -204,7 +204,7 @@ void version() { assertThat(result.hits()) .isNotEmpty() .allSatisfy(hit -> assertThat(hit).extracting(SearchHit::id, InstanceOfAssertFactories.STRING) - .startsWith("/versions/2.7/guides/")); + .startsWith("/version/2.7/guides/")); result = given() .queryParam("q", "orm") .queryParam("version", "main") @@ -215,7 +215,7 @@ void version() { assertThat(result.hits()) .isNotEmpty() .allSatisfy(hit -> assertThat(hit).extracting(SearchHit::id, InstanceOfAssertFactories.STRING) - .startsWith("/versions/main/guides/")); + .startsWith("/version/main/guides/")); } @Test diff --git a/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java b/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java index 768f52d7..9d86f5d0 100644 --- a/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java +++ b/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java @@ -94,7 +94,7 @@ void fetchQuarkusIo() throws Exception { Set.of("topic1", "topic2"), Set.of("io.quarkus:extension1", "io.quarkus:extension2"), FETCHED_GUIDE_1_CONTENT), - isGuide("/versions/2.7/guides/" + FETCHED_GUIDE_2_NAME, + isGuide("/version/2.7/guides/" + FETCHED_GUIDE_2_NAME, "Some other title", null, "keyword3, keyword4",