简体   繁体   English

nofollow links 与 tca 的链接向导

[英]nofollow links with link wizard of tca

is there a possibility to add rel="nofollow" to external links made with the link wizard from tca in the backend?是否有可能将 rel="nofollow" 添加到使用后端 tca 的链接向导创建的外部链接? (EG Link for Headlines in all content elements, link on images, external link in page tree). (EG所有内容元素中的标题链接、图像链接、页面树中的外部链接)。

The only way i found was the link handler in ck_editor.我发现的唯一方法是 ck_editor 中的链接处理程序。

Thanks!谢谢!

I forked the extension noopener and made some adjustments to allow TypoScript configuration.我分叉了扩展noopener并进行了一些调整以允许 TypoScript 配置。 As of now the TypoScript is not included yet but I post here the options:截至目前,TypoScript 尚未包括在内,但我在这里发布了选项:

config.tx_noopener {
  useDefaultRelAttribute = false
  relAttribute = nofollow
}

useDefaultRelAttribute is boolean (only false or 0 triggers something). useDefaultRelAttribute是 boolean (只有 false 或 0 触发某些东西)。
relAttribute can be any string, also with spaces. relAttribute可以是任何字符串,也可以是空格。

With this TypoScript-option it's possible to configure it different for specific pages.使用此 TypoScript 选项,可以针对特定页面对其进行不同的配置。

The extension is available here: https://github.com/DavidBruchmann/noopener .该扩展程序可在此处获得: https://github.com/DavidBruchmann/noopener
After adding TypoScript I will make a pull request to the original extension.添加 TypoScript 后,我将对原始扩展发出拉取请求。

EDIT:编辑:
If you have access to configure single links like headlines, you can add now one or several css-classes with prefix rel- .如果您有权配置单个链接(如标题),您现在可以添加一个或多个带有前缀rel-的 css 类。 If you enable the handling by noopener those classes will be used to create the rel -Attribute.如果您启用noopener处理,这些类将用于创建rel -Attribute。
Furthermore you can configure if the classes shall be removed then from the classes-attribute.此外,您可以配置是否应从类属性中删除类。

Example:例子:
I added a title in a content-element and a link in the corresponding field below.我在内容元素中添加了一个title ,并在下面的相应字段中添加了一个链接。 For the link I added these classes rel-nofollow rel-something col-right kunterbunt .对于链接,我添加了这些类rel-nofollow rel-something col-right kunterbunt
This is the TypoScriptSetup:这是 TypoScriptSetup:

config.tx_noopener {
  useDefaultRelAttribute = false
  # relAttribute = nofollow
  useCssClass = 1
  keepCssRelClass = 0
}

The option useCssClass dis- or enables the handling by css-class completely.选项useCssClass dis- or 完全启用 css-class 处理。
keepCssRelClass determines if the value shall be removed from the class-attribut when it's used for the rel-attribute. keepCssRelClass确定在用于 rel 属性时是否应从类属性中删除该值。
Additional the values in the class-attribute are only accepted if in the list of allowed values for the a-element according to this list:另外,只有在根据此列表的 a 元素的允许值列表中,才接受 class-attribute 中的值:
https://developer.mozilla.org/en-US/docs/Web/HTML/Link_typeshttps://developer.mozilla.org/en-US/docs/Web/HTML/Link_types

I know this filter might be undesired for some cases like lightbox where some other keywords are used but doing it without filter looked a bit scary and insecure for me, as it would enable editors to enter everything.我知道这个过滤器在某些情况下可能是不受欢迎的,比如使用其他关键字的灯箱,但不使用过滤器对我来说看起来有点可怕和不安全,因为它会使编辑器输入所有内容。 But keep in mind that the extension noopener is used only for external links, usage for internal links is in general possible but would change the basic idea of the extension.但请记住,扩展noopener仅用于外部链接,内部链接的使用通常是可能的,但会改变扩展的基本思想。

The result from the configured link above is this:上面配置的链接的结果是这样的:

<a rel="nofollow" href="..." class="rel-something col-right kunterbunt">...</a>

As you can see, the css-class rel-nofollow is shifted to the rel -attribute, rel-something is left untouched as it's not in the list of allowed values and the other css-classes never have the rel -prefix anyway.如您所见,css-class rel-nofollow被转移到rel -attribute, rel-something保持不变,因为它不在允许值列表中,并且其他 css-classes 无论如何都没有rel -prefix。

EDIT编辑
The pull request can be found here: https://github.com/georgringer/noopener/pull/6拉取请求可以在这里找到: https://github.com/georgringer/noopener/pull/6

Solving your question without extension first I thought about TypoScript lib.parseFunc .首先解决您的问题而无需扩展我想到了 TypoScript lib.parseFunc
The fluid-templates are just parsed without that function and you have to adjust the templates.流体模板只是在没有 function 的情况下解析,您必须调整模板。 Looking in the ViewHelper TypoLinkViewHelper you can see a list of allowed arguments:查看 ViewHelper TypoLinkViewHelper可以看到允许的 arguments 列表:


    public function initializeArguments()
    {
        $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
        $this->registerArgument('target', 'string', '', false, '');
        $this->registerArgument('class', 'string', '', false, '');
        $this->registerArgument('title', 'string', '', false, '');
        $this->registerArgument('additionalParams', 'string', '', false, '');
        $this->registerArgument('additionalAttributes', 'array', '', false, []);
        $this->registerArgument('useCacheHash', 'bool', '', false, false);
        $this->registerArgument('addQueryString', 'bool', '', false, false);
        $this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
        $this->registerArgument('addQueryStringExclude', 'string', '', false, '');
        $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
    }

The word external is not existing in the VH, so I assume you had to extend it and use your own VH. VH 中不存在external一词,因此我假设您必须对其进行扩展并使用您自己的 VH。 I never verified what the extension(s) for those purposes are doing in detail, probably they use some hook or service as they probably never require change of the templates.我从未详细验证用于这些目的的扩展程序在做什么,可能他们使用了一些钩子或服务,因为他们可能永远不需要更改模板。
I tried to change the Partial-template for the headlines and it works, just the separation between internal and external links is missing without further changes.我尝试更改标题的部分模板并且它有效,只是缺少内部和外部链接之间的分隔,无需进一步更改。

Template files reside in typo3/sysext/fluid_styled_content/Resources/Private and you could copy them into an own extension and change the default location accordingly.模板文件位于typo3/sysext/fluid_styled_content/Resources/Private中,您可以将它们复制到自己的扩展中并相应地更改默认位置。

<f:if condition="{header}">
    <f:switch expression="{layout}">
        <f:case value="1">
            <h1 class="{positionClass}">
                <f:link.typolink parameter="{link}">{header}</f:link.typolink>
            </h1>
        </f:case>
        <f:case value="2">
            <h2 class="{positionClass}">
                <f:link.typolink parameter="{link}" additionalAttributes="{rel:'nofollow'}">{header}</f:link.typolink>
            </h2>
        </f:case>
        ...

So probably the usage of the extension noopener proposed by @Julian Hofmann is the best and smartest solution.因此,@Julian Hofmann 提出的扩展noopener的使用可能是最好和最聪明的解决方案。 if you never need only a few but general changes.如果您从不需要一些但一般的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM