Commit f332dc66 authored by Jae's avatar Jae
Browse files

Add webring instructions

parent 96f53e87
# Implementation of the ftech webring
This is how to implement the Ftech webring.
In your HTML page, add the following and replace `site` with your website URL.
```html
<webring-css site="https://example.com">
Please activate JavaScript to enable the webring widget.
</webring-css>
```
Now, add a Javascript script to your webpage containing:
```javascript
const template = document.createElement("template");
template.innerHTML = `
<style>
.webring {
border: 15px solid #fff;
padding: 1rem;
display: grid;
grid-template-columns: 1fr 4fr 1fr;
grid-gap: 1rem;
text-align: center;
font: 100% system-ui, sans-serif;
}
.icon {
font-size: 100px;
}
.webring a {
color: #f5a500;
}
</style>
<div class="webring">
<div class="icon">></div>
<div id="copy">
</div>
<div class="icon"><</div>
</div>`;
const RING_MEMBERS = "https://jae.fi/webring/members"
class WebRing extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(template.content.cloneNode(true));
const thisSite = this.getAttribute("site");
fetch(RING_MEMBERS)
.then((response) => response.json())
.then((sites) => {
// Find the current site in the data
const matchedSiteIndex = sites.findIndex(
(site) => site.url === thisSite
);
const matchedSite = sites[matchedSiteIndex];
let prevSiteIndex = matchedSiteIndex - 1;
if (prevSiteIndex === -1) prevSiteIndex = sites.length - 1;
let nextSiteIndex = matchedSiteIndex + 1;
if (nextSiteIndex > sites.length) nextSiteIndex = 0;
const randomSiteIndex = this.getRandomInt(0, sites.length - 1);
const cp = `
<h1>Ftech webring</h1>
<p>
This is <a href="${matchedSite.url}">${matchedSite.name}</a>, owned by ${matchedSite.owner}
</p>
<p>
<a href="${sites[prevSiteIndex].url}">[Prev]</a>
<a href="${sites[nextSiteIndex].url}">[Next]</a>
<a href="${sites[randomSiteIndex].url}">[Random]</a>
</p>
`;
this.shadowRoot
.querySelector("#copy")
.insertAdjacentHTML("afterbegin", cp);
});
}
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
window.customElements.define("webring-css", WebRing);
```
Now, you should be able to see the webring widget and get random members.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment