Skip to content

Commit

Permalink
Merge pull request #20 from refinedmods/release/0.4.1
Browse files Browse the repository at this point in the history
Release v0.4.1
  • Loading branch information
raoulvdberge authored Aug 16, 2024
2 parents 41c2351 + ca74af6 commit ac6ef80
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.4.1] - 2024-08-16

### Fixed

- Articles are retrieved from snapshot version if possible.
- Playbook filename is now a command line argument. Default is `playbook.json`.

## [0.4.0] - 2024-08-15

### Added
Expand Down Expand Up @@ -70,7 +77,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Initial release.

[Unreleased]: https://github.com/refinedmods/refinedsites/compare/v0.4.0...HEAD
[Unreleased]: https://github.com/refinedmods/refinedsites/compare/v0.4.1...HEAD

[0.4.1]: https://github.com/refinedmods/refinedsites/compare/v0.4.0...v0.4.1

[0.4.0]: https://github.com/refinedmods/refinedsites/compare/v0.3.0...v0.4.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void main(final String[] args) {
log.info("Loading playbook from {}", args[0]);
final Path rootPath = Paths.get(args[0]);
final SiteFactory siteFactory = new SiteFactory(rootPath);
final Site site = siteFactory.getSite();
final Site site = siteFactory.getSite(args.length == 2 ? args[1] : "playbook.json");
log.info("Loaded site {}", site);
final Renderer renderer = new Renderer(rootPath, rootPath.resolve("output/"), site.getUrl());
renderer.render(site);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public String getAssetsOutputPath() {
public String getRelativePagePath(final Path from, final Path to) {
return from.relativize(to).toString().replace(".adoc", ".html");
}

@Override
public String toString() {
return name + "@" + version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class SiteFactory {

private final Path rootPath;

public Site getSite() {
public Site getSite(final String playbookJsonFilename) {
try {
log.info("Loading playbook");
final Path playbookPath = rootPath.resolve("playbook.json");
final Path playbookPath = rootPath.resolve(playbookJsonFilename);
final PlaybookConfig json = GSON.fromJson(Files.readString(playbookPath), PlaybookConfig.class);
log.info("Loaded playbook");
final List<Component> components = json.getComponents().stream().flatMap(component -> {
Expand Down
62 changes: 44 additions & 18 deletions src/main/java/com/refinedmods/refinedsites/render/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,27 @@ public void render(final Site site) {
for (final Component component : site.getComponents()) {
renderComponentPre(component);
}
for (final Component component : site.getComponents()) {
renderComponent(component, assetsPath, site, sitemapIndex);
final var components = site.getComponents()
.stream()
.collect(Collectors.groupingBy(Component::getName));
for (final var entry : components.entrySet()) {
log.info("Rendering versions of component {}", entry.getKey());
final List<Component> componentVersions = entry.getValue();
final Component snapshotComponent = componentVersions.stream()
.filter(c -> c.getVersion().snapshot())
.findFirst()
.orElse(null);
List<ArticleRender> articles = null;
if (snapshotComponent != null) {
articles = renderComponent(snapshotComponent, assetsPath, site, sitemapIndex, null);
log.info("Reusing {} articles from snapshot in other components", articles.size());
}
for (final Component component : componentVersions) {
if (component == snapshotComponent) {
continue;
}
renderComponent(component, assetsPath, site, sitemapIndex, articles);
}
}
sitemapIndex.write();
Files.writeString(outputPath.resolve("robots.txt"), "Sitemap: " + url + "/sitemap_index.xml");
Expand Down Expand Up @@ -149,10 +168,11 @@ private void renderComponentPre(final Component component) {
component.setSlug(componentSlug);
}

private void renderComponent(final Component component,
final Path assetsOutputPath,
final Site site,
final SitemapIndexGenerator sitemapIndex)
private List<ArticleRender> renderComponent(final Component component,
final Path assetsOutputPath,
final Site site,
final SitemapIndexGenerator sitemapIndex,
@Nullable final List<ArticleRender> articles)
throws IOException {
log.info("Rendering component {}", component);
final Path componentOutputPath = getComponentOutputPath(component);
Expand Down Expand Up @@ -192,18 +212,9 @@ private void renderComponent(final Component component,
infosByPageType.computeIfAbsent(singleInfo.type(), k -> new ArrayList<>()).add(singleInfo);
}
prepareNavigationItems(component.getNavigationItems(), pageInfo);
final List<ArticleRender> articles = infosByPageType.getOrDefault("article", Collections.emptyList())
.stream()
.map(info -> new ArticleRender(
info.title(),
info.description(),
info.relativePath(),
info.date().orElse(LocalDate.EPOCH)
))
.sorted(Comparator.comparing(ArticleRender::getDate).reversed())
.toList();

writeRssFeed(component, sitemapBaseUrl, articles, componentOutputPath);
final List<ArticleRender> theArticles = articles == null ? getArticles(infosByPageType) : articles;
writeRssFeed(component, sitemapBaseUrl, theArticles, componentOutputPath);

for (final Path pagePath : component.getPages()) {
renderPage(
Expand All @@ -217,13 +228,28 @@ private void renderComponent(final Component component,
releaseMatchingComponentVersion,
sitemapBaseUrl,
componentSitemap,
articles
theArticles
);
}
if (componentSitemap != null) {
componentSitemap.write();
sitemapIndex.addUrl(sitemapBaseUrl + "/sitemap.xml", renderDate);
}

return theArticles;
}

private static List<ArticleRender> getArticles(final Map<String, List<PageInfo>> infosByPageType) {
return infosByPageType.getOrDefault("article", Collections.emptyList())
.stream()
.map(info -> new ArticleRender(
info.title(),
info.description(),
info.relativePath(),
info.date().orElse(LocalDate.EPOCH)
))
.sorted(Comparator.comparing(ArticleRender::getDate).reversed())
.toList();
}

private static void writeRssFeed(final Component component,
Expand Down

0 comments on commit ac6ef80

Please sign in to comment.