Skip to content

Commit 8eb6ccf

Browse files
authored
Merge pull request #2865 from canonical/data-nosnippet
feat: added data-nosnippet tags
2 parents b339778 + 2f30a84 commit 8eb6ccf

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

static/js/cookie-policy-with-callback.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
*/
55
import { v4 as uuidv4 } from "uuid";
66

7+
// The cookie banner markup comes from the @canonical/cookie-policy package,
8+
// so it can't be tagged in our templates. Watch for it being inserted (and
9+
// re-inserted, since it's recreated each time it's opened) and mark it
10+
// nosnippet so it isn't pulled into search/AI page summaries.
11+
function watchCookieBanner() {
12+
new MutationObserver((mutations) => {
13+
for (const mutation of mutations) {
14+
for (const node of mutation.addedNodes) {
15+
if (node.nodeType === 1 && node.matches(".cookie-policy")) {
16+
node.setAttribute("data-nosnippet", "");
17+
}
18+
}
19+
}
20+
}).observe(document.body, { childList: true });
21+
}
22+
23+
if (document.body) {
24+
watchCookieBanner();
25+
} else {
26+
document.addEventListener("DOMContentLoaded", watchCookieBanner);
27+
}
28+
729
const getCookie = (targetCookie) =>
830
document.cookie.match(new RegExp("(^| )" + targetCookie + "=([^;]+)"));
931
let cookieAcceptanceValue = getCookie("_cookies_accepted");

templates/docs/shared/_footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="p-strip is-dark l-footer--sticky">
2-
<footer class="row">
2+
<footer class="row" data-nosnippet>
33
<div class="col-3">
44
<p>
55
Copyright &copy; {{ now("%Y") }}

templates/navigation/navigation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% set page_bubble = get_current_page_bubble(request.path).page_bubble %}
22

33
<header id="navigation"
4+
data-nosnippet
45
class="p-navigation{% if page_bubble %}--reduced{% else %}--sliding{% endif %} is-dark">
56
<div class="p-navigation__row--25-75">
67
<div class="p-navigation__banner">

templates/navigation/secondary-navigation.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div id="secondary-navigation"
2-
class="p-navigation is-sticky is-secondary is-dark">
2+
class="p-navigation is-sticky is-secondary is-dark"
3+
data-nosnippet>
34
<div class="p-navigation__row--25-75">
45
<div class="p-navigation__banner">
56
<div class="p-navigation__tagged-logo">

templates/partial/_footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<footer class="p-footer l-footer--sticky is-dark">
1+
<footer class="p-footer l-footer--sticky is-dark" data-nosnippet>
22
<div class="row">
33
<div class="col-4 col-small-4 u-hide--large">
44
<ul class="p-inline-list-icons u-no-padding--left u-no-margin--left">

0 commit comments

Comments
 (0)