Skip to content

Commit

Permalink
extension design and registration (#3)
Browse files Browse the repository at this point in the history
#### What type of PR is this?
/kind feature
#### What this PR does / why we need it:
此 PR 完成了代码的自模型定义和注册
#### Which issue(s) this PR fixes:
Fixes #2 
#### Does this PR introduce a user-facing change?
```release-note
None
```
  • Loading branch information
CaiHaosen authored Jul 4, 2024
1 parent a5e22b0 commit 6cc79e2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
48 changes: 48 additions & 0 deletions src/main/java/run/halo/injection/HtmlInjection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package run.halo.injection;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Set;
import lombok.Data;
import lombok.EqualsAndHashCode;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;

@Data
@EqualsAndHashCode(callSuper = true)
@GVK(group = "theme.halo.run",
version = "v1alpha1",
kind = "HtmlInjection",
plural = "htmlinjections",
singular = "htmlinjection")
public class HtmlInjection extends AbstractExtension {

@Schema(requiredMode = REQUIRED)
private Spec spec;

@Data
public static class Spec {
@Schema(description = "The name of the code snippet", maxLength = 100)
private String name;

@Schema(description = "The description of the code snippet", maxLength = 500)
private String description;

@Schema(description = "The content of the HTML")
private String fragment;

@Schema(description = "where to inject", allowableValues = {"HEADER", "FOOTER"})
private InjectionPoint injectionPoint;

@Schema(description = "The pages where the code snippet should be injected")
private Set<String> pageRules;

@Schema(description = "Whether the code snippet is enabled", defaultValue = "false")
private boolean enabled;
}

public enum InjectionPoint {
HEADER, FOOTER
}
}
24 changes: 21 additions & 3 deletions src/main/java/run/halo/injection/InjectionPlugin.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package run.halo.injection;
import org.pf4j.PluginWrapper;

import org.springframework.stereotype.Component;
import run.halo.app.extension.Scheme;
import run.halo.app.extension.SchemeManager;
import run.halo.app.plugin.BasePlugin;
import run.halo.app.plugin.PluginContext;


@Component
public class InjectionPlugin extends BasePlugin {
public InjectionPlugin(PluginWrapper wrapper) {
super(wrapper);
private final SchemeManager schemeManager;

public InjectionPlugin(PluginContext pluginContext, SchemeManager schemeManager) {
super(pluginContext);
this.schemeManager = schemeManager;
}

@Override
public void start() {
schemeManager.register(HtmlInjection.class);
}

@Override
public void stop() {
schemeManager.unregister(Scheme.buildFromType(HtmlInjection.class));
}
}

0 comments on commit 6cc79e2

Please sign in to comment.