Public
Script
v7
February 29, 2024
Readme
Ribbon element used by @andreterron/codeOnValTown
ribbonElement({val: { handle: "andre", name: "foo" }})
- define which val to link to;ribbonElement()
- infer the val from the call stack.
Example: @andreterron/openable_element
import { ribbonElement } from "https://esm.town/v/andreterron/codeOnVT_ribbonElement?v=3";
import { html } from "https://esm.town/v/stevekrouse/html?v=5";
export default async (req: Request): Promise<Response> => {
return html(`
<h2>Hello world!</h2>
<style>* { font-family: sans-serif }</style>
${ribbonElement()}
`);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { rootValRef } from "https://esm.town/v/andreterron/rootValRef?v=3";
import { ValRef } from "https://esm.town/v/andreterron/ValRef?v=1";
export function ribbonElement({ val, style }: { val?: ValRef; style?: string } = {}) {
const valRef = val?.handle && val?.name ? val : rootValRef();
if (!valRef) {
console.error("Failed to infer val. Please set the val parameter to the desired `{ handle, name }`");
return "";
}
const valSlug = `${valRef.handle}/${valRef.name}`;
return `
<div id="code-on-vt-host">
<template shadowrootmode="open">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css"
/>
${style ? `<style>${style}</style>` : ""}
<a
href="https://www.val.town/v/${valSlug}"
rel="source"
target="_blank"
class="github-fork-ribbon"
data-ribbon="Code on Val Town"
title="Code on Val Town"
>
Code on Val Town
</a>
</template>
</div>`;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v7
February 29, 2024
Can we make it machine-readable by decorating it with the appropriate
rel
attribute? 💡Possible ways to do that would be:
DCTerms.source
relation:code-repository
relationsource
relationPersonally, I would pick the third option because val is not really a code-repository, and adding an extra link element kinnda feels wrong 🤷 ♂️
Added the third option!
Awesome! Now I just need to build webextension to parse those
rel
-s and show the confetti effect on every detected occurrence 😎