Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public TocItem firstNonIndexPage() {
.orElse(null);
}

public Optional<TocItem> firstPageInChapter(String dirName) {
return tocItems.stream()
.filter(tocItem -> tocItem.getDirName().equals(dirName))
.findFirst();
}

public void removeTocItem(String dirName, String fileNameWithoutExtension) {
tocItems.removeIf(item -> item.match(dirName, fileNameWithoutExtension));
}
Expand Down Expand Up @@ -139,6 +145,13 @@ public List<TocItem> getTocItems() {
return Collections.unmodifiableList(tocItems);
}

public Set<String> getAllDirNames() {
return tocItems.stream()
.map(TocItem::getDirName)
.filter(dirName -> !dirName.isEmpty())
.collect(toSet());
}

public Collection<Path> getResolvedPaths() {
return tocItemByPath.keySet();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add: Generate index.html files for chapters to automatically redirect to the first page
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.testingisdocumenting.znai.utils.JsonUtils;
import org.testingisdocumenting.znai.parser.MarkupParsingConfiguration;
import org.testingisdocumenting.znai.parser.MarkupParsingConfigurations;
import org.testingisdocumenting.znai.utils.ResourceUtils;
import org.testingisdocumenting.znai.website.modifiedtime.FileBasedPageModifiedTime;
import org.testingisdocumenting.znai.website.modifiedtime.PageModifiedTimeStrategy;

Expand Down Expand Up @@ -200,6 +201,7 @@ private void registerPreprocessor() {
public void deploy() {
reportPhase("deploying documentation");
generatePages();
generateChapterIndexRedirectPages();
generateSearchIndex();
generateLlmContent();
deployToc();
Expand Down Expand Up @@ -634,6 +636,22 @@ private void generatePages() {
buildJsonOfAllPages();
}

private void generateChapterIndexRedirectPages() {
reportPhase("generating chapter index redirect pages");

Set<String> dirNames = toc.getAllDirNames();
dirNames.forEach(dirName -> {
toc.firstPageInChapter(dirName).ifPresent((tocItem) -> {
String redirectUrl = docStructure.fullUrl(
tocItem.getDirName() + "/" + tocItem.getFileNameWithoutExtension());
String redirectPage = ResourceUtils.textContent("template/redirect.html")
.replace("${newUrl}", redirectUrl);

deployer.deploy(dirName + "/index.html", redirectPage);
});
});
}

private void generateSearchIndex() {
reportPhase("generating search index");

Expand Down
10 changes: 10 additions & 0 deletions znai-website-gen/src/main/resources/template/redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=${newUrl}">
<title>redirecting...</title>
</head>
<body>
</body>
</html>