|
1 | 1 | {% extends "base.html" %} |
2 | 2 |
|
| 3 | +{#- |
| 4 | + Visits from the maintainers are tagged so that the Internal Traffic data |
| 5 | + filter in Google Analytics can drop them. Opening any page with ?internal=1 |
| 6 | + stores a flag in localStorage, ?internal=0 removes it, and while the flag is |
| 7 | + there every event carries traffic_type=internal. The docs under |
| 8 | + /cpp-linter-action/, /clang-tools-pip/, /cpp-linter-rs/ and /cpp-linter/ are |
| 9 | + on the same origin and read the same flag. It runs before Material's own |
| 10 | + snippet, so the setting is queued ahead of the first page_view. |
| 11 | +-#} |
| 12 | + |
| 13 | +{% block analytics %} |
| 14 | + {% if config.extra.analytics %} |
| 15 | + <script> |
| 16 | + try { |
| 17 | + var param = new URLSearchParams(location.search).get("internal"); |
| 18 | + if (param === "1") localStorage.setItem("cpp-linter-internal", "1"); |
| 19 | + if (param === "0") localStorage.removeItem("cpp-linter-internal"); |
| 20 | + if (localStorage.getItem("cpp-linter-internal") === "1") { |
| 21 | + window.dataLayer = window.dataLayer || []; |
| 22 | + (function () { dataLayer.push(arguments); })("set", { traffic_type: "internal" }); |
| 23 | + } |
| 24 | + } catch (e) { |
| 25 | + // localStorage is unavailable when storage is blocked; the visit is then not tagged. |
| 26 | + } |
| 27 | + </script> |
| 28 | + {% endif %} |
| 29 | + {{ super() }} |
| 30 | +{% endblock %} |
| 31 | + |
3 | 32 | {#- |
4 | 33 | The site's fonts are self-hosted in docs/fonts and declared in shared.css: |
5 | 34 | Instrument Sans for text, JetBrains Mono for code and Bricolage Grotesque for |
6 | 35 | headings. theme.font is false in mkdocs.yml, so Material loads nothing itself. |
7 | 36 | Preloading the latin files for text and headings lets the browser fetch them |
8 | 37 | while it is still reading the stylesheets. The URLs must match the ones in |
9 | 38 | shared.css, and crossorigin is required for fonts even on the same origin. |
| 39 | + |
| 40 | + The Open Graph and Twitter tags give links shared in chats and on social |
| 41 | + sites a title, a description and the card in static/og-image.png. Pages with |
| 42 | + no URL of their own, like the 404 page, leave og:url out. |
10 | 43 | -#} |
11 | 44 |
|
12 | 45 | {% block extrahead %} |
13 | 46 | {{ super() }} |
14 | 47 | <link rel="preload" href="{{ 'fonts/instrument-sans-latin.woff2' | url }}" as="font" type="font/woff2" crossorigin> |
15 | 48 | <link rel="preload" href="{{ 'fonts/bricolage-grotesque-latin.woff2' | url }}" as="font" type="font/woff2" crossorigin> |
| 49 | + {%- if page and page.meta and page.meta.title %} |
| 50 | + {%- set og_title = page.meta.title %} |
| 51 | + {%- elif page and page.title and not page.is_homepage %} |
| 52 | + {%- set og_title = page.title | striptags %} |
| 53 | + {%- else %} |
| 54 | + {%- set og_title = config.site_name %} |
| 55 | + {%- endif %} |
| 56 | + {%- set og_description = (page.meta.description if page and page.meta and page.meta.description) or config.site_description %} |
| 57 | + {%- set og_image = config.site_url ~ "static/og-image.png" %} |
| 58 | + <meta property="og:type" content="website"> |
| 59 | + <meta property="og:site_name" content="{{ config.site_name }}"> |
| 60 | + <meta property="og:title" content="{{ og_title }}"> |
| 61 | + <meta property="og:description" content="{{ og_description }}"> |
| 62 | + {%- if page and page.canonical_url %} |
| 63 | + <meta property="og:url" content="{{ page.canonical_url }}"> |
| 64 | + {%- endif %} |
| 65 | + <meta property="og:image" content="{{ og_image }}"> |
| 66 | + <meta property="og:image:width" content="1200"> |
| 67 | + <meta property="og:image:height" content="630"> |
| 68 | + <meta property="og:image:alt" content="cpp-linter: clang-format and clang-tidy for C/C++ pull requests, pre-commit hooks and CI"> |
| 69 | + <meta name="twitter:card" content="summary_large_image"> |
| 70 | + <meta name="twitter:title" content="{{ og_title }}"> |
| 71 | + <meta name="twitter:description" content="{{ og_description }}"> |
| 72 | + <meta name="twitter:image" content="{{ og_image }}"> |
| 73 | +{% endblock %} |
| 74 | + |
| 75 | +{#- |
| 76 | + Copying a code block is how a reader takes cpp-linter into a project, so each |
| 77 | + copy is sent to Google Analytics as a copy_code event. snippet names the |
| 78 | + section the block is in (the id of the nearest heading above it, or the |
| 79 | + block's own id on the home page), and code_title is the file name shown above |
| 80 | + the block, when it has one. |
| 81 | +-#} |
| 82 | + |
| 83 | +{% block scripts %} |
| 84 | + {{ super() }} |
| 85 | + {% if config.extra.analytics %} |
| 86 | + <script> |
| 87 | + document.addEventListener("click", function (event) { |
| 88 | + var button = event.target.closest && |
| 89 | + event.target.closest('.md-code__button[data-md-type="copy"], .md-clipboard, .cl-copy'); |
| 90 | + if (!button) return; |
| 91 | + var block = button.closest(".highlight, .cl-window"); |
| 92 | + var snippet = ""; |
| 93 | + if (button.classList.contains("cl-copy")) { |
| 94 | + snippet = (button.getAttribute("data-clipboard-target") || "").replace(/^#/, ""); |
| 95 | + } else if (block) { |
| 96 | + var headings = document.querySelectorAll("article h2[id], article h3[id]"); |
| 97 | + for (var i = 0; i < headings.length; i++) { |
| 98 | + if (headings[i].compareDocumentPosition(block) & Node.DOCUMENT_POSITION_FOLLOWING) { |
| 99 | + snippet = headings[i].id; |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + var title = block && block.querySelector(".filename, .cl-window__file"); |
| 104 | + window.dataLayer = window.dataLayer || []; |
| 105 | + (function () { dataLayer.push(arguments); })("event", "copy_code", { |
| 106 | + snippet: snippet || "(none)", |
| 107 | + code_title: title ? title.textContent.trim() : "(none)" |
| 108 | + }); |
| 109 | + }); |
| 110 | + </script> |
| 111 | + {% endif %} |
16 | 112 | {% endblock %} |
0 commit comments