Merge branch 'main' into chore/remove-deprecated-code

pull/7469/head
Ryan Wang 2025-05-26 21:15:25 +08:00 committed by GitHub
commit c27cbb5204
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 7 deletions

View File

@ -63,13 +63,12 @@ class SystemConfigFirstExternalUrlSupplier implements ExternalUrlSupplier {
@Override @Override
public URI get() { public URI get() {
try { try {
if (externalUrl != null) {
return externalUrl.toURI();
}
if (!haloProperties.isUseAbsolutePermalink()) { if (!haloProperties.isUseAbsolutePermalink()) {
return URI.create(getBasePath()); return URI.create(getBasePath());
} }
if (externalUrl != null) {
return externalUrl.toURI();
}
return haloProperties.getExternalUrl().toURI(); return haloProperties.getExternalUrl().toURI();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw Exceptions.propagate(e); throw Exceptions.propagate(e);

View File

@ -55,7 +55,7 @@ class SystemConfigFirstExternalUrlSupplierTest {
} }
@Test @Test
void getURIWhenBasePathSetAndNotUsingAbsolutePermalink() throws MalformedURLException { void getURIWhenBasePathSetAndNotUsingAbsolutePermalink() {
when(webFluxProperties.getBasePath()).thenReturn("/blog"); when(webFluxProperties.getBasePath()).thenReturn("/blog");
when(haloProperties.isUseAbsolutePermalink()).thenReturn(false); when(haloProperties.isUseAbsolutePermalink()).thenReturn(false);
@ -137,10 +137,11 @@ class SystemConfigFirstExternalUrlSupplierTest {
class SystemConfigSupplier { class SystemConfigSupplier {
@Test @Test
void shouldGetUrlCorrectly() throws Exception { void shouldGetUrlWhenUseAbsolutePermalink() throws Exception {
var basic = new SystemSetting.Basic(); var basic = new SystemSetting.Basic();
basic.setExternalUrl("https://www.halo.run"); basic.setExternalUrl("https://www.halo.run");
when(systemConfigFetcher.getBasic()).thenReturn(Mono.just(basic)); when(systemConfigFetcher.getBasic()).thenReturn(Mono.just(basic));
when(haloProperties.isUseAbsolutePermalink()).thenReturn(true);
externalUrl.onExtensionInitialized(null); externalUrl.onExtensionInitialized(null);
assertEquals(URI.create("https://www.halo.run").toURL(), externalUrl.getRaw()); assertEquals(URI.create("https://www.halo.run").toURL(), externalUrl.getRaw());
assertEquals(URI.create("https://www.halo.run"), externalUrl.get()); assertEquals(URI.create("https://www.halo.run"), externalUrl.get());
@ -150,6 +151,22 @@ class SystemConfigFirstExternalUrlSupplierTest {
externalUrl.getURL(mockRequest)); externalUrl.getURL(mockRequest));
} }
@Test
void shouldGetUrlWhenNotUsingAbsolutePermalink() throws MalformedURLException {
var basic = new SystemSetting.Basic();
basic.setExternalUrl("https://www.halo.run");
when(systemConfigFetcher.getBasic()).thenReturn(Mono.just(basic));
when(haloProperties.isUseAbsolutePermalink()).thenReturn(false);
when(webFluxProperties.getBasePath()).thenReturn("/fake");
externalUrl.onExtensionInitialized(null);
assertEquals(URI.create("https://www.halo.run").toURL(), externalUrl.getRaw());
assertEquals(URI.create("/fake"), externalUrl.get());
var mockRequest = mock(HttpRequest.class);
assertEquals(URI.create("https://www.halo.run").toURL(),
externalUrl.getURL(mockRequest));
}
} }
} }

View File

@ -25,6 +25,7 @@ const href = computed({
props.editor.commands.setLink({ props.editor.commands.setLink({
href: value, href: value,
target: target.value ? "_blank" : "_self", target: target.value ? "_blank" : "_self",
rel: rel.value ? "nofollow" : "",
}); });
}, },
}); });
@ -38,6 +39,21 @@ const target = computed({
props.editor.commands.setLink({ props.editor.commands.setLink({
href: href.value, href: href.value,
target: value ? "_blank" : "_self", target: value ? "_blank" : "_self",
rel: rel.value ? "nofollow" : "",
});
},
});
const rel = computed({
get() {
const attrs = props.editor.getAttributes("link");
return attrs?.rel === "nofollow";
},
set(value) {
props.editor.commands.setLink({
href: href.value,
target: target.value ? "_blank" : "_self",
rel: value ? "nofollow" : "",
}); });
}, },
}); });
@ -66,6 +82,7 @@ const handleLinkBubbleButton = () => {
props.editor.commands.setLink({ props.editor.commands.setLink({
href: text, href: text,
target: "_self", target: "_self",
rel: "",
}); });
} }
} }
@ -100,7 +117,7 @@ const handleLinkBubbleButton = () => {
:placeholder="i18n.global.t('editor.extensions.link.placeholder')" :placeholder="i18n.global.t('editor.extensions.link.placeholder')"
class="bg-gray-50 rounded-md hover:bg-gray-100 block px-2 w-full py-1.5 text-sm text-gray-900 border border-gray-300 focus:ring-blue-500 focus:border-blue-500" class="bg-gray-50 rounded-md hover:bg-gray-100 block px-2 w-full py-1.5 text-sm text-gray-900 border border-gray-300 focus:ring-blue-500 focus:border-blue-500"
/> />
<label class="inline-flex items-center mt-2"> <label class="inline-flex items-center mt-2 mr-2">
<input <input
v-model="target" v-model="target"
type="checkbox" type="checkbox"
@ -110,6 +127,17 @@ const handleLinkBubbleButton = () => {
{{ i18n.global.t("editor.extensions.link.open_in_new_window") }} {{ i18n.global.t("editor.extensions.link.open_in_new_window") }}
</span> </span>
</label> </label>
<label class="inline-flex items-center mt-2">
<!-- nofollow -->
<input
v-model="rel"
type="checkbox"
class="form-checkbox text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
/>
<span class="ml-2 text-sm text-gray-500">
{{ i18n.global.t("editor.extensions.link.nofollow") }}
</span>
</label>
</div> </div>
</template> </template>
</VDropdown> </VDropdown>

View File

@ -14,6 +14,10 @@ const Link = TiptapLink.extend<ExtensionOptions & LinkOptions>({
}; };
}, },
renderHTML({ HTMLAttributes }) {
return ["a", HTMLAttributes, 0];
},
addPasteRules() { addPasteRules() {
// Remove the function of pasted text parsing as a link // Remove the function of pasted text parsing as a link
return []; return [];

View File

@ -33,6 +33,7 @@ editor:
placeholder: 链接地址 placeholder: 链接地址
open_in_new_window: 在新窗口中打开 open_in_new_window: 在新窗口中打开
cancel_link: 取消链接 cancel_link: 取消链接
nofollow: 搜索引擎忽略链接关系
audio: audio:
disable_autoplay: 关闭自动播放 disable_autoplay: 关闭自动播放
enable_autoplay: 开启自动播放 enable_autoplay: 开启自动播放