-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from refinedmods/release/0.3.0
Release v0.3.0
- Loading branch information
Showing
4 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/refinedmods/refinedsites/render/ImageTreeprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.refinedmods.refinedsites.render; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.asciidoctor.ast.Document; | ||
import org.asciidoctor.ast.StructuralNode; | ||
import org.asciidoctor.extension.Treeprocessor; | ||
|
||
@RequiredArgsConstructor | ||
public class ImageTreeprocessor extends Treeprocessor { | ||
private final Path currentPageSourcePath; | ||
private final Path currentPageOutputPath; | ||
private final Map<Path, Path> sourceToDestinationAssets; | ||
|
||
@Override | ||
public Document process(final Document document) { | ||
processBlock(document); | ||
return document; | ||
} | ||
|
||
private void processBlock(final StructuralNode block) { | ||
final List<StructuralNode> blocks = block.getBlocks(); | ||
for (int i = 0; i < blocks.size(); i++) { | ||
final StructuralNode currentBlock = blocks.get(i); | ||
if ("image".equals(currentBlock.getContext())) { | ||
final Path sourcePath = currentPageSourcePath.getParent().resolve( | ||
(String) currentBlock.getAttribute("target") | ||
).normalize(); | ||
final Path destinationPath = sourceToDestinationAssets.get(sourcePath); | ||
if (destinationPath == null) { | ||
throw new RuntimeException("Asset " + sourcePath + " not found"); | ||
} | ||
final Path relativePath = currentPageOutputPath.getParent().relativize(destinationPath); | ||
currentBlock.setAttribute("target", relativePath.toString(), true); | ||
} else { | ||
processBlock(currentBlock); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters