Skip to content

Commit

Permalink
Merge pull request #31 from yrodiere/version-versions
Browse files Browse the repository at this point in the history
Use the correct `/version/` instead of `/versions/` in guide HTTP paths
  • Loading branch information
yrodiere authored Oct 27, 2023
2 parents 3c43127 + 0b0c511 commit 6d3ead1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
23 changes: 10 additions & 13 deletions src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,24 @@ public Stream<Guide> guides() throws IOException {
@SuppressWarnings("resource")
private Stream<GuidesDirectory> 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,
Expand All @@ -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<String> toSet(String value) {
if (value == null || value.isBlank()) {
return Set.of();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/quarkus/search/app/SearchServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6d3ead1

Please sign in to comment.