-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension design and registration (#3)
#### 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
Showing
2 changed files
with
69 additions
and
3 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
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 | ||
} | ||
} |
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 |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
|