diff --git a/application/src/main/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplier.java b/application/src/main/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplier.java index 8f354dd93..b7a3a2337 100644 --- a/application/src/main/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplier.java +++ b/application/src/main/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplier.java @@ -63,13 +63,12 @@ class SystemConfigFirstExternalUrlSupplier implements ExternalUrlSupplier { @Override public URI get() { try { - if (externalUrl != null) { - return externalUrl.toURI(); - } if (!haloProperties.isUseAbsolutePermalink()) { return URI.create(getBasePath()); } - + if (externalUrl != null) { + return externalUrl.toURI(); + } return haloProperties.getExternalUrl().toURI(); } catch (URISyntaxException e) { throw Exceptions.propagate(e); diff --git a/application/src/test/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplierTest.java b/application/src/test/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplierTest.java index 9c2c36671..97a87619a 100644 --- a/application/src/test/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplierTest.java +++ b/application/src/test/java/run/halo/app/infra/SystemConfigFirstExternalUrlSupplierTest.java @@ -55,7 +55,7 @@ class SystemConfigFirstExternalUrlSupplierTest { } @Test - void getURIWhenBasePathSetAndNotUsingAbsolutePermalink() throws MalformedURLException { + void getURIWhenBasePathSetAndNotUsingAbsolutePermalink() { when(webFluxProperties.getBasePath()).thenReturn("/blog"); when(haloProperties.isUseAbsolutePermalink()).thenReturn(false); @@ -137,10 +137,11 @@ class SystemConfigFirstExternalUrlSupplierTest { class SystemConfigSupplier { @Test - void shouldGetUrlCorrectly() throws Exception { + void shouldGetUrlWhenUseAbsolutePermalink() throws Exception { var basic = new SystemSetting.Basic(); basic.setExternalUrl("https://www.halo.run"); when(systemConfigFetcher.getBasic()).thenReturn(Mono.just(basic)); + when(haloProperties.isUseAbsolutePermalink()).thenReturn(true); externalUrl.onExtensionInitialized(null); assertEquals(URI.create("https://www.halo.run").toURL(), externalUrl.getRaw()); assertEquals(URI.create("https://www.halo.run"), externalUrl.get()); @@ -150,6 +151,22 @@ class SystemConfigFirstExternalUrlSupplierTest { 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)); + } + } } \ No newline at end of file diff --git a/ui/packages/editor/src/extensions/link/LinkBubbleButton.vue b/ui/packages/editor/src/extensions/link/LinkBubbleButton.vue index dfbec50d1..66a95ac34 100644 --- a/ui/packages/editor/src/extensions/link/LinkBubbleButton.vue +++ b/ui/packages/editor/src/extensions/link/LinkBubbleButton.vue @@ -25,6 +25,7 @@ const href = computed({ props.editor.commands.setLink({ href: value, target: target.value ? "_blank" : "_self", + rel: rel.value ? "nofollow" : "", }); }, }); @@ -38,6 +39,21 @@ const target = computed({ props.editor.commands.setLink({ href: href.value, 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({ href: text, target: "_self", + rel: "", }); } } @@ -100,7 +117,7 @@ const handleLinkBubbleButton = () => { :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" /> -