Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions js/forum-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ document.addEventListener("DOMContentLoaded", async function () {
loadingText.textContent = "Loading FAQs...";
list.parentElement.insertBefore(loadingText, list);

function isSafeUrl(url) {
try {
var parsed = new URL(url, window.location.origin);
return parsed.protocol === "https:" || parsed.protocol === "http:";
} catch (e) {
return false;
}
}

try {
const res = await fetch("/assets/data/faq.json");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
Expand Down Expand Up @@ -50,7 +59,7 @@ document.addEventListener("DOMContentLoaded", async function () {
}

function renderTopics() {
list.innerHTML = "";
list.replaceChildren();

const shown = filteredTopics.slice(0, visibleCount);

Expand All @@ -72,22 +81,39 @@ document.addEventListener("DOMContentLoaded", async function () {
? t.excerpt
: "No description available.";

card.innerHTML = `
<h4 style="margin-bottom:8px;">
<strong>${t.title}</strong>
</h4>
<p style="color:#333;line-height:1.4;">
${excerpt}
<a href="${t.url}" target="_blank" rel="noopener noreferrer"
style="text-decoration:none;color:#0069c2;" data-noicon>
Read more
</a>
</p>
<p style="color:#666;font-size:0.9em;">
Last updated: ${new Date(t.last_posted_at).toLocaleDateString("en-GB")} |
Replies: ${t.posts_count} | Views: ${t.views}
</p>
`;
var h4 = document.createElement("h4");
h4.style.cssText = "margin-bottom:8px;";
var strong = document.createElement("strong");
strong.textContent = t.title;
h4.appendChild(strong);

var excerptP = document.createElement("p");
excerptP.style.cssText = "color:#333;line-height:1.4;";
excerptP.textContent = excerpt + " ";
var readMore = document.createElement("a");
if (isSafeUrl(t.url)) {
readMore.setAttribute("href", t.url);
}
readMore.setAttribute("target", "_blank");
readMore.setAttribute("rel", "noopener noreferrer");
readMore.style.cssText = "text-decoration:none;color:#0069c2;";
readMore.dataset.noicon = "";
readMore.textContent = "Read more";
excerptP.appendChild(readMore);

var metaP = document.createElement("p");
metaP.style.cssText = "color:#666;font-size:0.9em;";
metaP.textContent =
"Last updated: " +
new Date(t.last_posted_at).toLocaleDateString("en-GB") +
" | Replies: " +
t.posts_count +
" | Views: " +
t.views;

card.appendChild(h4);
card.appendChild(excerptP);
card.appendChild(metaP);
list.appendChild(card);
});

Expand All @@ -103,7 +129,7 @@ document.addEventListener("DOMContentLoaded", async function () {
list.appendChild(btn);
}

// 🧽 JS-based CSS injection to remove external icon pseudo-element
// JS-based CSS injection to remove external icon pseudo-element
if (!document.getElementById("noicon-style")) {
const style = document.createElement("style");
style.id = "noicon-style";
Expand Down
47 changes: 37 additions & 10 deletions js/github-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Get the updated field of an entry of the feed and format it like "Jan 1, 1970"
function formatDate(updated) {
// Extract the date and create a Date object
date = new Date(updated);
var date = new Date(updated);

// Names for the months (we do not need an external library just for this)
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
Expand All @@ -27,12 +27,23 @@ var github_api_endpoint = 'https://api.github.com/repos/precice/precice/releases
fetch(github_api_endpoint).then(function(response) {
if (response.ok) {
response.json().then(function(data) {
tag = data[0].name;
published_at = data[0].published_at;
url = data[0].html_url
// Format the text, which contains the link, the title, and the date.
var text = '<a href="' + url + '" class="btn btn-secondary no-icon action-button" role="button" target="_blank" rel="noopener noreferrer">Latest ' + tag + ' (' + formatDate(published_at) + ') &nbsp;<i class="fas fa-download"></i></a>';
document.getElementById('latest-release').innerHTML = text;
var tag = data[0].name;
var published_at = data[0].published_at;
var url = data[0].html_url;

var link = document.createElement('a');
link.setAttribute('href', url);
link.className = 'btn btn-secondary no-icon action-button';
link.setAttribute('role', 'button');
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
link.appendChild(document.createTextNode('Latest ' + tag + ' (' + formatDate(published_at) + ') \u00A0'));
var icon = document.createElement('i');
icon.className = 'fas fa-download';
link.appendChild(icon);

var container = document.getElementById('latest-release');
container.replaceChildren(link);
});
}
else throw new Error("Problem with fetching releases");
Expand All @@ -54,9 +65,25 @@ document.addEventListener("DOMContentLoaded", function() {
fetch(github_api_endpoint).then(function(response) {
if (response.ok) {
response.json().then(function(data) {
count = data.stargazers_count
var text = '<a href="https://github.com/precice/precice/" class="btn btn-default no-icon action-button" role="button" target="_blank" rel="noopener noreferrer">Star on GitHub &nbsp;<i class="fas fa-star"></i><span id="stargazers"> ' + count + '</span></a>';
document.getElementById('github-button').innerHTML = text;
var count = data.stargazers_count;

var link = document.createElement('a');
link.setAttribute('href', 'https://github.com/precice/precice/');
link.className = 'btn btn-default no-icon action-button';
link.setAttribute('role', 'button');
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
link.appendChild(document.createTextNode('Star on GitHub \u00A0'));
var icon = document.createElement('i');
icon.className = 'fas fa-star';
link.appendChild(icon);
var span = document.createElement('span');
span.id = 'stargazers';
span.textContent = ' ' + count;
link.appendChild(span);

var container = document.getElementById('github-button');
container.replaceChildren(link);
});
}
else throw new Error("Problem with fetching stargazers");
Expand Down
39 changes: 34 additions & 5 deletions js/news-collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ document.addEventListener("DOMContentLoaded", async function () {
const newsContainer = document.getElementById("news-container");
const loadingText = document.getElementById("loading-news");

function isSafeUrl(url) {
try {
var parsed = new URL(url, window.location.origin);
return parsed.protocol === "https:" || parsed.protocol === "http:";
} catch (e) {
return false;
}
}

try {
const response = await fetch("/assets/data/news.json");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
Expand All @@ -22,12 +31,32 @@ document.addEventListener("DOMContentLoaded", async function () {

const date = new Date(topic.created_at || topic.last_posted_at).toLocaleDateString("en-GB");

card.innerHTML = `<a href="${topic.url}" target="_blank" rel="noopener noreferrer" class="news-link no-external-marker">
<h4><strong>${topic.title}</strong></h4>
<p>${topic.description}</p>
<p class="text-muted"><small>${date}</small></p>
</a>`;
const link = document.createElement("a");
if (isSafeUrl(topic.url)) {
link.setAttribute("href", topic.url);
}
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noopener noreferrer");
link.className = "news-link no-external-marker";

const h4 = document.createElement("h4");
const strong = document.createElement("strong");
strong.textContent = topic.title;
h4.appendChild(strong);

const descP = document.createElement("p");
descP.textContent = topic.description;

const dateP = document.createElement("p");
dateP.className = "text-muted";
const small = document.createElement("small");
small.textContent = date;
dateP.appendChild(small);

link.appendChild(h4);
link.appendChild(descP);
link.appendChild(dateP);
card.appendChild(link);
col.appendChild(card);
newsContainer.appendChild(col);
}
Expand Down