refactor: uinify some properties of plugins and themes (#4061)

#### What type of PR is this?
/kind improvement
/area core
/milestone 2.7.x
/kind api-change

#### What this PR does / why we need it:
统一主题和插件描述文件的部分字段
1. 统一网站字段为 homepage,将主题的 website 标记为过时并兼容为 homepage
2. 主题添加 license 字段
3. 插件添加 repo

#### Which issue(s) this PR fixes:
Fixes #4011

#### Does this PR introduce a user-facing change?
```release-note
统一主题和插件描述文件的部分字段
```
pull/4104/head^2
guqing 2023-06-26 22:33:58 +08:00 committed by GitHub
parent ff7ab4e4f1
commit 2791d2f0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 9 deletions

View File

@ -61,7 +61,7 @@ public class Plugin extends AbstractExtension {
* *
* @see <a href="semver.org">semantic version</a> * @see <a href="semver.org">semantic version</a>
*/ */
@Schema(required = true, pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-(" @Schema(requiredMode = REQUIRED, pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-("
+ "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\." + "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\."
+ "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\" + "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\"
+ ".[0-9a-zA-Z-]+)*))?$") + ".[0-9a-zA-Z-]+)*))?$")
@ -75,6 +75,8 @@ public class Plugin extends AbstractExtension {
private String homepage; private String homepage;
private String repo;
private String description; private String description;
private List<License> license; private List<License> license;
@ -94,6 +96,10 @@ public class Plugin extends AbstractExtension {
private String configMapName; private String configMapName;
} }
/**
* In the future, we may consider using {@link run.halo.app.infra.model.License} instead of it.
* But now, replace it will lead to incompatibility with downstream.
*/
@Data @Data
public static class License { public static class License {
private String name; private String name;

View File

@ -1,6 +1,7 @@
package run.halo.app.core.extension; package run.halo.app.core.extension;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List; import java.util.List;
@ -14,6 +15,7 @@ import org.springframework.util.Assert;
import run.halo.app.extension.AbstractExtension; import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK; import run.halo.app.extension.GVK;
import run.halo.app.infra.ConditionList; import run.halo.app.infra.ConditionList;
import run.halo.app.infra.model.License;
/** /**
* <p>Theme extension.</p> * <p>Theme extension.</p>
@ -42,18 +44,21 @@ public class Theme extends AbstractExtension {
public static class ThemeSpec { public static class ThemeSpec {
private static final String WILDCARD = "*"; private static final String WILDCARD = "*";
@Schema(required = true, minLength = 1) @Schema(requiredMode = REQUIRED, minLength = 1)
private String displayName; private String displayName;
@Schema(required = true) @Schema(requiredMode = REQUIRED)
private Author author; private Author author;
private String description; private String description;
private String logo; private String logo;
@Deprecated(forRemoval = true, since = "2.7.0")
private String website; private String website;
private String homepage;
private String repo; private String repo;
private String version; private String version;
@ -69,6 +74,8 @@ public class Theme extends AbstractExtension {
private String configMapName; private String configMapName;
private List<License> license;
@Schema @Schema
private CustomTemplates customTemplates; private CustomTemplates customTemplates;
@ -89,6 +96,13 @@ public class Theme extends AbstractExtension {
} }
return StringUtils.defaultString(this.require, WILDCARD); return StringUtils.defaultString(this.require, WILDCARD);
} }
/**
* Compatible with {@link #website} property.
*/
public String getHomepage() {
return StringUtils.defaultString(this.homepage, this.website);
}
} }
@Data @Data
@ -125,7 +139,7 @@ public class Theme extends AbstractExtension {
@ToString @ToString
public static class Author { public static class Author {
@Schema(required = true, minLength = 1) @Schema(requiredMode = REQUIRED, minLength = 1)
private String name; private String name;
private String website; private String website;
@ -138,7 +152,6 @@ public class Theme extends AbstractExtension {
private List<TemplateDescriptor> page; private List<TemplateDescriptor> page;
} }
/** /**
* Type used to describe custom template page. * Type used to describe custom template page.
* *
@ -148,14 +161,14 @@ public class Theme extends AbstractExtension {
@Data @Data
public static class TemplateDescriptor { public static class TemplateDescriptor {
@Schema(required = true, minLength = 1) @Schema(requiredMode = REQUIRED, minLength = 1)
private String name; private String name;
private String description; private String description;
private String screenshot; private String screenshot;
@Schema(required = true, minLength = 1) @Schema(requiredMode = REQUIRED, minLength = 1)
private String file; private String file;
} }

View File

@ -0,0 +1,12 @@
package run.halo.app.infra.model;
import lombok.Data;
/**
* Common data objects for license.
*/
@Data
public class License {
private String name;
private String url;
}

View File

@ -39,7 +39,7 @@ class ThemeTest {
themeSpec.setRepo("https://test.com"); themeSpec.setRepo("https://test.com");
themeSpec.setLogo("https://test.com"); themeSpec.setLogo("https://test.com");
themeSpec.setWebsite("https://test.com"); themeSpec.setHomepage("https://test.com");
themeSpec.setDescription("test-description"); themeSpec.setDescription("test-description");
themeSpec.setConfigMapName("test-config-map"); themeSpec.setConfigMapName("test-config-map");
themeSpec.setSettingName("test-setting"); themeSpec.setSettingName("test-setting");
@ -56,7 +56,7 @@ class ThemeTest {
}, },
"description": "test-description", "description": "test-description",
"logo": "https://test.com", "logo": "https://test.com",
"website": "https://test.com", "homepage": "https://test.com",
"repo": "https://test.com", "repo": "https://test.com",
"version": "*", "version": "*",
"requires": "*", "requires": "*",

View File

@ -86,6 +86,12 @@ export interface PluginSpec {
* @memberof PluginSpec * @memberof PluginSpec
*/ */
pluginDependencies?: { [key: string]: string }; pluginDependencies?: { [key: string]: string };
/**
*
* @type {string}
* @memberof PluginSpec
*/
repo?: string;
/** /**
* *
* @type {string} * @type {string}

View File

@ -18,6 +18,9 @@ import { Author } from "./author";
// May contain unused imports in some cases // May contain unused imports in some cases
// @ts-ignore // @ts-ignore
import { CustomTemplates } from "./custom-templates"; import { CustomTemplates } from "./custom-templates";
// May contain unused imports in some cases
// @ts-ignore
import { License } from "./license";
/** /**
* *
@ -55,6 +58,18 @@ export interface ThemeSpec {
* @memberof ThemeSpec * @memberof ThemeSpec
*/ */
displayName: string; displayName: string;
/**
*
* @type {string}
* @memberof ThemeSpec
*/
homepage?: string;
/**
*
* @type {Array<License>}
* @memberof ThemeSpec
*/
license?: Array<License>;
/** /**
* *
* @type {string} * @type {string}
@ -96,6 +111,7 @@ export interface ThemeSpec {
* *
* @type {string} * @type {string}
* @memberof ThemeSpec * @memberof ThemeSpec
* @deprecated
*/ */
website?: string; website?: string;
} }