forked from Imago-Veritatis/Imago-Veritatis
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharticle.js
More file actions
73 lines (57 loc) · 2.34 KB
/
Copy patharticle.js
File metadata and controls
73 lines (57 loc) · 2.34 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { getFirestore, doc, getDoc } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js";
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
const firebaseConfig = {
apiKey: "AIzaSyBw7PSHW4fe2jptxyf7xHtyINSrYG_TupA",
authDomain: "rtl-world.firebaseapp.com",
projectId: "rtl-world",
storageBucket: "rtl-world.firebasestorage.app",
messagingSenderId: "1092619392407",
appId: "1:1092619392407:web:f968b6ef5416d66d6360d2",
measurementId: "G-4GBT38563H"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const urlParams = new URLSearchParams(window.location.search);
const articleId = urlParams.get("id");
showdown.extension('smallText', function() {
return [{
type: 'lang',
regex: /-# (.*?)(\n|$)/g,
replace: '<small>$1</small>$2<br>$2'
}];
});
async function loadArticle() {
if (!articleId) {
document.getElementById("article-content").innerHTML = "<p>Article introuvable</p>";
return;
}
const articleRef = doc(db, "articles", articleId);
const articleSnap = await getDoc(articleRef);
if (articleSnap.exists()) {
let article = articleSnap.data();
document.title = `RTL World - ${article.title}`;
document.getElementById("article-category").textContent = article.category;
let converter = new showdown.Converter({
simplifiedAutoLink: true,
strikethrough: true,
tables: true,
extensions: ['smallText']
});
let htmlContent = converter.makeHtml(article.content);
document.getElementById("article-content").innerHTML = `
<h1 class="article-title">${article.title}</h1>
<p class="article-meta">${article.author} - ${article.timestamp}</p>
<div class="article-body">${htmlContent}</div>
`;
if (article.image) {
let img = document.createElement("img");
img.src = article.image;
img.alt = "Planche";
img.classList.add("article-image");
document.body.appendChild(img);
}
} else {
document.getElementById("article-content").innerHTML = "<p>Article non trouvé</p>";
}
}
window.onload = loadArticle;