Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Language fallback handling for canonical and alternate language links #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ prototype(Neos.Seo:AlternateLanguageLinks) < prototype(Neos.Fusion:Component) {
@if.isDefaultLocale={props.defaultLocale == item.dimensions[props.dimension][0]}/>
<Neos.Seo:AlternateLanguageLink node={item.node}
@if.isNotAbsent={item.state != 'absent'}
@if.existsInTargetDimensions={item.node.dimensions == item.node.context.targetDimensionValues}
Copy link

@regniets regniets Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the hreflang specs. We need to remove hreflang in the "unlogic fallback" case as nothing points to this version.
Actually "@if.hasNoForeignCanonical" needs to be adapted as it does have a foreign canonical
https://developers.google.com/search/docs/advanced/crawling/localized-versions?hl=en

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't fully understand what needs to be done from your description.

Copy link

@regniets regniets Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually something like
@if.hasNoForeignCanonical = ${String.isBlank(q(this.node).property('canonicalLink'))}
@if.nodeIsTranslated = ${this.node.dimensions == this.node.context.targetDimensionValues}
... line 5

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, so an additional check for the canonical

Copy link

@mbiberger mbiberger Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the query @if.existsInTargetDimensions={item.node.dimensions == item.node.context.targetDimensionValues} no hreflang is output when I only adjust content on a page that has a language fallback.
We have now added the following queries in Neos.Seo:AlternateLanguageLink:
@if.hasMetaRobotsNoIndexNotSet = ${q(this.node).property('metaRobotsNoindex') || q(this.node).is('[instanceof Neos.Seo:NoindexMixin]') ? false : true} @if.hasNoForeignCanonical = ${String.isBlank(q(this.node).property('canonicalLink'))}

thanks to @regniets 😉

@if.notExcluded={!props.excludedPresets || Array.indexOf(props.excludedPresets, item.dimensions[props.dimension][0]) == -1}
hreflang={String.replace((item.preset ? item.preset.values[0] : item.dimensions[props.dimension][0]), props.dimensionValueSeparator, '-')}/>
`
Expand Down
12 changes: 11 additions & 1 deletion Resources/Private/Fusion/Metadata/CanonicalLink.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ prototype(Neos.Seo:CanonicalLink) < prototype(Neos.Fusion:Tag) {
attributes {
rel = 'canonical'
href = Neos.Fusion:Component {
node = ${documentNode}
node = Neos.Fusion:Case {
useFallback {
condition = ${node.dimensions != node.context.targetDimensionValues}
targetDimensions = ${Array.map(node.dimensions, (item) => item[0])}
renderer = ${q(node).context({dimensions: node.dimensions, targetDimensions: this.targetDimensions}).get(0)}
}
default {
condition = true
renderer = ${node}
}
}
canonicalLink = ${q(this.node).property('canonicalLink')}

renderer = Neos.Fusion:Case {
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Metadata/LangAttribute.fusion
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
prototype(Neos.Seo:LangAttribute) < prototype(Neos.Fusion:Value) {
value = ${String.replace(documentNode.context.dimensions.language[0], '_', '-')}
value = ${String.replace(documentNode.dimensions.language[0], '_', '-')}
@if.languageDimensionExists = ${Configuration.setting('Neos.ContentRepository.contentDimensions.language') != null}
@if.onlyRenderWhenInLiveWorkspace = ${node.context.workspace.name == 'live'}
}