From a7d22faf18bacc9dc564bb6fa31b5bc39ebc07c6 Mon Sep 17 00:00:00 2001
From: EpicKiwi
Date: Thu, 23 Jan 2025 11:47:05 +0100
Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20section=20"Plus=20d'infos"=20?=
=?UTF-8?q?et=20du=20r=C3=A9sum=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/archived-brochure.css | 18 +++++++++
src/brochure.template.html | 3 +-
src/data.js | 78 +++++++++++++++++++++++++++-----------
src/index.html | 71 +++++++++++++++++++++++++++++++---
src/index.js | 34 +++++++++--------
5 files changed, 161 insertions(+), 43 deletions(-)
create mode 100644 src/archived-brochure.css
diff --git a/src/archived-brochure.css b/src/archived-brochure.css
new file mode 100644
index 0000000..ae32fc8
--- /dev/null
+++ b/src/archived-brochure.css
@@ -0,0 +1,18 @@
+body {
+ width: 100%;
+ max-width: 800px;
+ padding: 15px;
+ box-sizing: border-box;
+
+ margin-left: auto;
+ margin-right: auto;
+ padding-top: 75px;
+}
+
+h2 {
+ margin-top: 75px;
+}
+
+h1 {
+ margin-bottom: 75px;
+}
\ No newline at end of file
diff --git a/src/brochure.template.html b/src/brochure.template.html
index 66d5749..d5203c9 100644
--- a/src/brochure.template.html
+++ b/src/brochure.template.html
@@ -3,13 +3,14 @@
+
— Archive Infokiosque
-
Archivée le
+ Télécharger
-
diff --git a/src/data.js b/src/data.js
index f5a1ae5..e414dc1 100644
--- a/src/data.js
+++ b/src/data.js
@@ -3,13 +3,61 @@ const PARSER = new DOMParser()
const SERIALIZER = new XMLSerializer()
const DATE_FORMATTER = new Intl.DateTimeFormat("fr", {dateStyle: "short"})
-export async function uploadDocument(documentFile, documentDetails = {}){
+const FEATURES = [
+ function titleFeature(doc, data){
+ doc.title = data.get("title") + " " + doc.title
+ },
+
+ function nameFeature(doc, data) {
+ doc.querySelector('[property="name"]').textContent = data.get("title")
+ },
+
+ function hrefFeature(doc, data) {
+ doc.querySelector('a[href="original.pdf"]').href = "./"+data.get("original-filename")
+ },
+
+ function uploadDateFeature(doc, data) {
+ let el = doc.querySelector('[property="uploadDate"]')
+ el.textContent = DATE_FORMATTER.format(new Date(data.get("upload-date")))
+ el.setAttribute("datetime", data.get("upload-date"));
+ el.setAttribute("content", data.get("upload-date"));
+ },
+
+ function authorFeature(doc, data){
+ if(!data.has("author"))
+ return
+
+ let el = doc.createElement("p")
+ el.append(doc.createTextNode("Par "))
+
+ let authorEl = doc.createElement("span")
+ authorEl.textContent = data.get("author")
+ authorEl.setAttribute("property", "author")
+ el.append(authorEl)
+
+ doc.querySelector("h1").insertAdjacentElement("afterend", el)
+ },
+
+ function abstractFeature(doc, data){
+ if(!data.has("abstract"))
+ return
+
+ let el = doc.createElement("p")
+ el.textContent = data.get("abstract")
+ el.setAttribute("property", "abstract")
+
+ doc.querySelector("h2").insertAdjacentElement("beforebegin", el)
+ }
+]
+
+export async function uploadDocument(documentFile, documentDetails = new FormData()){
let uniqueName = await getUniqueName(documentDetails)
let baseURI = new URL(`./${uniqueName}/`, DATA_URL)
- let originalFileName = `${slugify(documentDetails.title)}-original.pdf`
+ let originalFileName = `${slugify(documentDetails.get("title"))}-original.pdf`
+ documentDetails.set("original-filename", originalFileName)
let uploadProgress = fetch(new URL(`./${originalFileName}`, baseURI), {
method: "PUT",
@@ -21,22 +69,8 @@ export async function uploadDocument(documentFile, documentDetails = {}){
let page = PARSER.parseFromString(await (await fetch("/brochure.template.html")).text(), "text/html")
- page.title = documentDetails.title + " " + page.title
-
- page.querySelector('[property="name"]').textContent = documentDetails.title
- page.querySelector('a[href="original.pdf"]').href = "./"+originalFileName
-
- {
- let el = page.querySelector('[property="uploadDate"]')
- el.textContent = DATE_FORMATTER.format(new Date(documentDetails.uploadDate))
- el.setAttribute("datetime", documentDetails.uploadDate);
- el.setAttribute("content", documentDetails.uploadDate);
- }
-
- if(documentDetails.author){
- page.querySelector('[property="author"]').textContent = documentDetails.author
- } else {
- page.querySelector('[property="author"]').remove()
+ for(let feature of FEATURES){
+ feature(page, documentDetails)
}
let responses = await Promise.all([
@@ -86,12 +120,12 @@ function getRandomName(documentDetails){
crypto.getRandomValues(source)
let parts = [toHex(source)]
- if(documentDetails.author){
- parts.push(slugify(documentDetails.author))
+ if(documentDetails.get("author")){
+ parts.push(slugify(documentDetails.get("author")))
}
- if(documentDetails.title){
- parts.push(slugify(documentDetails.title))
+ if(documentDetails.get("title")){
+ parts.push(slugify(documentDetails.get("title")))
}
return parts.join("-")
diff --git a/src/index.html b/src/index.html
index fa3199a..278fe6b 100644
--- a/src/index.html
+++ b/src/index.html
@@ -4,6 +4,7 @@
Archive Infokiosque
+
@@ -47,10 +94,15 @@
-
+
+
+
@@ -61,13 +113,22 @@
+
+
-
+
-
-