There is some documentation here about how to set nofollow
on link documents:
However this article doesn't cover what I suspect is the main user case, which is setting nofollow
on links within text objects.
I also found this community question with the same issue. The suggested solution is to add a custom label to the text object, which I have done.
I have exactly the same problem as the poster above. I've set the label on my link and have this html element
<span class="nofollow">
<a href="https://www.exmaple.com" target="'_blank'" rel="noopener">Example</a>
</span>
I'm using Vue and I have the html-serializer setup form the default project. The problem I have now is that I cannot access the anchor element. For example, I can access the span element like this:
if (type === Elements.span) {
console.log(element);
}
But how do I access the a
element? The children
parameter is empty and the element parameter has nothing in I can see that would allow me to access the a
element. I also cannot find a way to access the span class.
Here is my whole serializer
/**
* To learn more about HTML Serializer check out the Prismic documentation
* https://prismic.io/docs/vuejs/beyond-the-api/html-serializer
*/
import prismicDOM from 'prismic-dom'
import linkResolver from './link-resolver'
const Elements = prismicDOM.RichText.Elements
export default function (type, element, content, children) {
if (type === Elements.heading1) {
var id = children.toString().toLowerCase().replace(/ /g, '');
return `<h1 id="${id}">${children}</h1>`;
}
if (type === Elements.heading2) {
var id = children.toString().toLowerCase().replace(/ /g, '');
return `<h2 id="${id}">${children}</h2>`;
}
if (type === Elements.span) {
console.log(element);
}
// Generate links to Prismic Documents as <router-link> components
// Present by default, it is recommended to keep this
if (type === Elements.hyperlink) {
let result = ''
const url = prismicDOM.Link.url(element.data, linkResolver)
if (element.data.link_type === 'Document') {
result = `<router-link to="${url}">${content}</router-link>`
} else {
const target = element.data.target ? `target="'${element.data.target}'" rel="noopener"` : ''
result = `<a href="${url}" ${target}>${content}</a>`
}
return result
}
// If the image is also a link to a Prismic Document, it will return a <router-link> component
// Present by default, it is recommended to keep this
if (type === Elements.image) {
let result = `<img src="${element.url}" alt="${element.alt || ''}" copyright="${element.copyright || ''}">`
if (element.linkTo) {
const url = prismicDOM.Link.url(element.linkTo, linkResolver)
if (element.linkTo.link_type === 'Document') {
result = `<router-link to="${url}">${result}</router-link>`
} else {
const target = element.linkTo.target ? `target="${element.linkTo.target}" rel="noopener"` : ''
result = `<a href="${url}" ${target}>${result}</a>`
}
}
const wrapperClassList = [element.label || '', 'block-img']
result = `<p class="${wrapperClassList.join(' ')}">${result}</p>`
return result
}
// Return null to stick with the default behavior for everything else
return null
}