Skip to content

Commit

Permalink
Fix links in INDEX.html
Browse files Browse the repository at this point in the history
  • Loading branch information
programming-wolf committed Nov 23, 2023
1 parent b5d81b2 commit 4fd6342
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/main/java/org/isaqb/asciidoc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,30 @@ public static void main(final String[] args) {
language,
projectVersion,
curriculumFileName,
versionDate
versionDate,
curriculumFileName
));
convertInLanguage(
ENGLISH,

convertInFormat(HTML,
projectVersion,
INDEX_FILE_NAME,
versionDate);
versionDate,
ENGLISH,
curriculumFileName);
}

private static void convertInLanguage(
final String language,
final String projectVersion,
final String curriculumFileName,
final String versionDate) {
final String versionDate,
final String curriculumName) {
Stream.of(FORMATS).forEach(format -> convertInFormat(
format, projectVersion,
curriculumFileName,
versionDate,
language
language,
curriculumName
));
}

Expand All @@ -77,11 +82,12 @@ private static void convertInFormat(
final String projectVersion,
final String curriculumFileName,
final String versionDate,
final String language) {
final String language,
final String curriculumName) {
try (final Asciidoctor asciidoctor = create()) {
final Attributes attributes = toAttributes(
projectVersion,
curriculumFileName,
curriculumName,
versionDate,
language);
asciidoctor.convertDirectory(
Expand All @@ -98,7 +104,9 @@ private static void convertInFormat(
.toDir(new File(OUTPUT_DIR))
.safe(SafeMode.UNSAFE)
.build());

if (!INDEX_FILE_NAME.equals(curriculumFileName)) {
// rename only if we're not creating the index file.
renameResultAccordingToLanguage(curriculumFileName, format, language);
}
}
Expand Down Expand Up @@ -147,11 +155,14 @@ private static void renameResultAccordingToLanguage(
final String format,
final String language) {
final File original = new File("%s%s.%s".formatted(OUTPUT_DIR, fileName, format));
final File renamed = new File("%s%s-%s.%s".formatted(OUTPUT_DIR, fileName, language.toLowerCase(), format));
final File renamed = new File(
"%s%s-%s.%s".formatted(OUTPUT_DIR, fileName, language.toLowerCase(), format));
if (!original.exists()) {
System.err.printf("Failed to rename result file %s as it does not exist", original.getAbsolutePath());
System.err.printf("Failed to rename result file %s as it does not exist",
original.getAbsolutePath());
} else if (!original.renameTo(renamed)) {
System.err.printf("Failed to rename result file %s to %s%n", original.getName(), renamed.getName());
System.err.printf("Failed to rename result file %s to %s%n", original.getName(),
renamed.getName());
}
original.deleteOnExit();
}
Expand Down

0 comments on commit 4fd6342

Please sign in to comment.