Skip to content

Commit

Permalink
Change outline share source
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 4, 2025
1 parent 9cd8ace commit d98c2d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
ARCHIVE_ENDPOINT: ${{ secrets.TEACON_ARCHIVE_ENDPOINT }}
ARCHIVE_ACCESS_KEY: ${{ secrets.TEACON_ARCHIVE_ACCESS_KEY }}
ARCHIVE_SECRET_KEY: ${{ secrets.TEACON_ARCHIVE_SECRET_KEY }}
TAG: ${{ github.ref_name }}
run: ./gradlew -Dorg.gradle.s3.endpoint=$ARCHIVE_ENDPOINT publishReleasePublicationToTeaconRepository githubActionOutput
- name: Generate Changelog
id: changelog
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/appeng/client/guidebook/Guide.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.BiFunction;
import java.util.function.Function;

import appeng.core.AppEng;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -308,7 +309,7 @@ public ReloadListener(ResourceLocation id) {
}

static final String apiBaseUrl = "https://wiki.teacon.cn/api/";
static final String shareId = "jiachen";
static final String shareId = "jiachen-tour-guide";
static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
static final Gson GSON = new Gson();

Expand All @@ -318,25 +319,27 @@ protected Map<ResourceLocation, ParsedGuidePage> prepare(ResourceManager resourc
profiler.startTick();
Map<ResourceLocation, ParsedGuidePage> pages = new HashMap<>();

HttpRequest listRequest = HttpRequest.newBuilder()
.uri(URI.create(apiBaseUrl + "documents.info"))
.POST(HttpRequest.BodyPublishers.ofString(GSON.toJson(
Map.of("apiVersion", 2, "shareId", shareId))))
.header("Content-Type", "application/json")
.build();
JsonObject listResponse;
try {
listResponse = JsonParser.parseString(HTTP_CLIENT.send(listRequest,
HttpResponse.BodyHandlers.ofString()).body()).getAsJsonObject();
} catch (IOException | InterruptedException e) {
LOGGER.error("Failed to fetch guidebook page list", e);
return pages;
}
JsonObject rootNode = listResponse.get("data").getAsJsonObject().get("sharedTree").getAsJsonObject();
try {
fetchSharedTreeNode(shareId, rootNode, "", pages);
} catch (IOException e) {
LOGGER.error("Failed to fetch online pages from shareId {}", shareId, e);
if (!shareId.isEmpty()) {
HttpRequest listRequest = HttpRequest.newBuilder()
.uri(URI.create(apiBaseUrl + "documents.info"))
.POST(HttpRequest.BodyPublishers.ofString(GSON.toJson(
Map.of("apiVersion", 2, "shareId", shareId))))
.header("Content-Type", "application/json")
.build();
JsonObject listResponse;
try {
listResponse = JsonParser.parseString(HTTP_CLIENT.send(listRequest,
HttpResponse.BodyHandlers.ofString()).body()).getAsJsonObject();
} catch (IOException | InterruptedException e) {
LOGGER.error("Failed to fetch guidebook page list", e);
return pages;
}
JsonObject rootNode = listResponse.get("data").getAsJsonObject().get("sharedTree").getAsJsonObject();
try {
fetchSharedTreeNode(shareId, rootNode, "", pages);
} catch (IOException e) {
LOGGER.error("Failed to fetch online pages from shareId {}", shareId, e);
}
}

var resources = resourceManager.listResources(folder,
Expand Down Expand Up @@ -402,6 +405,9 @@ private void fetchSharedTreeNode(String sourceId, JsonObject node, String parent
try {
ParsedGuidePage page = PageCompiler.parse(sourceId, pageId, fullBody);
pages.put(pageId, page);
if (pageSeq == 1) {
pages.put(AppEng.makeId("index.md"), page);
}
} catch (Exception ex) {
LOGGER.error("Failed to parse online page {}", pageId, ex);
return;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/appeng/client/guidebook/compiler/PageCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ private void compileFlowContent(LytFlowParent layoutParent, MdAstAnyContent cont
LytFlowContent layoutChild;
if (content instanceof MdAstText astText) {
var text = new LytFlowText();
text.setText(astText.value);
text.setText(astText.value
.replace("\\n", "\n")
.replace("\\", " ")
);
layoutChild = text;
} else if (content instanceof MdAstInlineCode astCode) {
var text = new LytFlowText();
Expand Down Expand Up @@ -393,13 +396,17 @@ public void handleError(String error) {
return link;
}

private static final String ALT_IMG_PATH_PREFIX = "ae2guide/";

@NotNull
private LytImage compileImage(MdAstImage astImage) {
var image = new LytImage();
image.setTitle(astImage.title);
image.setAlt(astImage.alt);
try {
var imageId = IdUtils.resolveLink(astImage.url, pageId);
var imageId = astImage.alt.trim().startsWith(ALT_IMG_PATH_PREFIX)
? IdUtils.resolveLink(astImage.alt.trim().substring(ALT_IMG_PATH_PREFIX.length()), pageId)
: IdUtils.resolveLink(astImage.url, pageId);
var imageContent = pages.loadAsset(imageId);
if (imageContent == null) {
LOGGER.error("Couldn't find image {}", astImage.url);
Expand Down

0 comments on commit d98c2d9

Please sign in to comment.