"Code on Val Town" Ribbon HTML Element

Ribbon element used by @andreterron/codeOnValTown

Usage

  • ribbonElement({val: { handle: "andre", name: "foo" }}) - define which val to link to;
  • ribbonElement() - infer the val from the call stack.

Example: @andreterron/openable_element

Create valimport { 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()} `); };
Readme
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>`;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
vladimyr avatar

Can we make it machine-readable by decorating it with the appropriate rel attribute? 💡

Possible ways to do that would be:

  1. adding another link element with DCTerms.source relation:
Create val<link rel="DCTERMS.source" href="https://www.val.town/v/${valSlug}">
  1. decorating anchor element with code-repository relation
Create val<a href="https://www.val.town/v/${valSlug}" rel="code-repository" target="_blank" class="github-fork-ribbon" data-ribbon="Code on Val Town" title="Code on Val Town" >
  1. decorating anchor element with proposed source relation
Create val<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" >

Personally, I would pick the third option because val is not really a code-repository, and adding an extra link element kinnda feels wrong 🤷‍♂️

andreterron avatar

Added the third option!

vladimyr avatar

Awesome! Now I just need to build webextension to parse those rel-s and show the confetti effect on every detected occurrence 😎