Skip to content

Commit

Permalink
Add proper schema org stuff to code blocks due to use of meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
whitep4nth3r committed Feb 11, 2025
1 parent ba4aea9 commit e1c7ab1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/_client_scripts/copy_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const copyButtons = document.querySelectorAll(`[data-copy]`);
copyButtons.forEach((button) => {
button.addEventListener("click", (e) => {
const codeId = e.target.dataset.copy;
const codeAsText = document.querySelector(`[data-code-id=${codeId}]`).dataset.codeToCopy;
const codeAsText = document.querySelector(`[data-code-id=${codeId}]`).getAttribute("content");
navigator.clipboard.writeText(decodeURIComponent(codeAsText));
});
});
});
7 changes: 5 additions & 2 deletions src/_components/codeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ const CodeBlock = ({ code, lang, isDiff }) => {
Copy
</span>
</button>
<div data-code-block>
<div data-code-block itemscope itemtype="https://schema.org/SoftwareSourceCode">
<meta itemprop="codeSampleType" content="snippet">
<meta itemprop="programmingLanguage" content="${lang}">
<meta data-code-id="${thisCodeId}" itemprop="text" content="${encodeURIComponent(code)}">
${HighlightPairedShortcode(code, `${prefix}${lang}`)}
</div>
</div>
<meta data-code-id="${thisCodeId}" data-code-to-copy="${encodeURIComponent(code)}">
`;
};

Expand Down
2 changes: 1 addition & 1 deletion src/_css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/_css/main.css.map

Large diffs are not rendered by default.

0 comments on commit e1c7ab1

Please sign in to comment.