Skip to content

Commit ac5e9fe

Browse files
committed
♻️ Foreground vditor render implement with ReactivePostContentHandler
1 parent 5eb2bfe commit ac5e9fe

File tree

5 files changed

+59
-68
lines changed

5 files changed

+59
-68
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repositories {
1616
}
1717

1818
dependencies {
19-
implementation platform('run.halo.tools.platform:plugin:2.6.0-SNAPSHOT')
19+
implementation platform('run.halo.tools.platform:plugin:2.7.0-SNAPSHOT')
2020
compileOnly 'run.halo.app:api'
2121

2222
testImplementation 'run.halo.app:api'
@@ -38,4 +38,4 @@ task buildFrontend(type: PnpmTask) {
3838
build {
3939
// build frontend before build
4040
tasks.getByName('compileJava').dependsOn('buildFrontend')
41-
}
41+
}

console/src/views/Vditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const debounceOnUpdate = () => {
3030
}
3131
3232
onMounted(() => {
33-
vditor.value = new Vditor(vditor.value, {
33+
vditor.value = new Vditor(vditorRef.value, {
3434
height: "calc(100vh - 56px)",
3535
toolbarConfig: {
3636
pin: true,

src/main/java/top/mczhengyi/vditor/VditorHeadProcessor.java

-65
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package top.mczhengyi.vditor;
2+
3+
import com.google.common.base.Throwables;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.stereotype.Component;
8+
import reactor.core.publisher.Mono;
9+
import run.halo.app.plugin.ReactiveSettingFetcher;
10+
import run.halo.app.theme.ReactivePostContentHandler;
11+
12+
@Component
13+
@AllArgsConstructor
14+
@Slf4j
15+
public class VditorPostContentHandler implements ReactivePostContentHandler {
16+
17+
private final ReactiveSettingFetcher reactiveSettingFetcher;
18+
19+
@Override
20+
public Mono<PostContentContext> handle(PostContentContext contentContext) {
21+
return reactiveSettingFetcher.fetch("basic", BasicConfig.class)
22+
.map(basicConfig -> {
23+
if (basicConfig.enable_render) {
24+
contentContext.setContent(renderScript() + "\n" + contentContext.getContent());
25+
}
26+
return contentContext;
27+
})
28+
.onErrorResume(e -> {
29+
log.error("VditorHeadProcessor process failed", Throwables.getRootCause(e));
30+
return Mono.empty();
31+
});
32+
}
33+
34+
private String renderScript() {
35+
return """
36+
<link rel="stylesheet" href="/plugins/vditor-mde/assets/static/index.css" />
37+
<script src="/plugins/vditor-mde/assets/static/method.min.js"></script>
38+
<script src="/plugins/vditor-mde/assets/static/render.js"></script>
39+
""";
40+
}
41+
42+
@Data
43+
public static class BasicConfig {
44+
Boolean enable_render;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: plugin.halo.run/v1alpha1
2+
kind: ExtensionDefinition
3+
metadata:
4+
name: ext-def-vditor-post-content
5+
spec:
6+
className: top.mczhengyi.vditor.VditorPostContentHandler
7+
# 文章内容扩展点的名称,固定值
8+
extensionPointName: reactive-post-content-handler
9+
displayName: "VditorPostContentHandler"
10+
description: "Vditor render support for post content"

0 commit comments

Comments
 (0)