diff --git a/app.py b/app.py index 89d088d..cbbadfb 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,10 @@ from flask import Flask, render_template, request, redirect, make_response, \ Markup -from enum import Enum from bs4 import BeautifulSoup -import re +import json +from util.status import Status +from util.manip import Manip +#from util.genHtml import GenerationHtml __author__ = "rick@gnous.eu | Romain" __licence__ = "GPL3 or later" @@ -10,42 +12,33 @@ __licence__ = "GPL3 or later" app = Flask('ui', static_url_path="/static") app.config['TEMPLATES_AUTO_RELOAD'] = True -class Status(Enum): - ERREUR_LIEN = "Le lien doit être en http ou https et valide !" - ERREUR_INCONNUE = "Une erreur inconnue a été rencontrée !" - BON = "Lien ajouté !" +fichierJson = "listeLiens.json" +listeCategorie = ["autres", "informatique", "musique"] -class Manip(): - def ecritureFichierHtml(nouvLien, cheminFichier): - nouvLienHtml = BeautifulSoup(nouvLien, "html.parser") - with open(cheminFichier, 'r+') as file: - soup = BeautifulSoup(file, 'html.parser') - soup.find("hr").insert_after("", nouvLienHtml) - file.seek(0) - file.write(soup.prettify()) - - def valideUrl(url: str) -> bool: - # thx django - regex = re.compile( - r'^(?:http|ftp)s?://' # http:// or https:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... - r'localhost|' # localhost... - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4 - r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6 - r'(?::\d+)?' # optional port - r'(?:/?|[/?]\S+)$', re.IGNORECASE) - - return bool(re.search(regex, url)) +manip = Manip(fichierJson) +#generateurHml = GenerationHtml(fichierJson, listeCategorie) @app.route('/') def slash(): - response = make_response(app.send_static_file("index.html")) + with open(fichierJson, 'r') as fichier: + liens = json.load(fichier) + listeLiens = liens["liens"] + listeLiens.reverse() + response = make_response(render_template("index.html", listeLiens=listeLiens)) response.headers["Content-Security-Policy"] = "default-src 'self'" return response @app.route("/categories/") def categories(subpath): - return app.send_static_file(subpath + ".html") + if subpath in listeCategorie: + listeLiensCategorie = [] + with open(fichierJson, 'r') as fichierLiens: + listeLiens = json.load(fichierLiens) + for lien in listeLiens["liens"]: + if lien["categorie"] == subpath: + listeLiensCategorie.append(lien) + listeLiensCategorie.reverse() + return render_template("index.html", listeLiens=listeLiensCategorie) @app.route("/ajout") def ajout(): @@ -62,27 +55,24 @@ def bizutage_redirect(): @app.route("/bizutage", methods=["POST"]) def bizutage(): lien = request.values["lien"] - if not Manip.valideUrl(lien): - return render_template( - "ajout.html", - erreur=Status.ERREUR_LIEN.value - ) titre = Markup.escape(request.values["titre"]) desc = Markup.escape(request.values["desc"]) categorie = Markup.escape(request.values["categories"]) - nouvLien = f"""
-

{titre}

-

{lien}

-
-

{desc}

-
""" - Manip.ecritureFichierHtml(nouvLien, "static/index.html") - Manip.ecritureFichierHtml(nouvLien, "static/" + categorie + ".html") - Manip.ecritureFichierHtml(nouvLien, "lite/index.html") - Manip.ecritureFichierHtml(nouvLien, "lite/" + categorie + ".html") - return render_template("ajout.html", reussi=Status.BON.value) + nouvLien = {"titre": titre, + "url": lien, + "desc": desc, + "categorie": categorie, + "tags": [] + } + + ret = manip.ajoutLienJson(nouvLien) + if ret is Status.BON: + #generateurHml.majTousFichiers() + return render_template("ajout.html", reussi=ret.value) + else: + return render_template("ajout.html", erreur=ret.value) if __name__ == "__main__": app.run() diff --git a/listeLiens.json b/listeLiens.json new file mode 100644 index 0000000..542a60f --- /dev/null +++ b/listeLiens.json @@ -0,0 +1,3 @@ +{ + "liens": [] +} diff --git a/lite/ajout.html b/lite/ajout.html deleted file mode 100644 index 71d0aa3..0000000 --- a/lite/ajout.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - Ajout - - - -
- -
- - - - -
- - diff --git a/lite/apropos.html b/lite/apropos.html deleted file mode 100644 index be782f3..0000000 --- a/lite/apropos.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - A propos - - - -
- -

Fonctionnalités futures :

- -

Site en alpha. Futurs ajouts :

- -

Vous pouvez me proposer des ajouts en ouvrant un ticket sur le git ou en envoyant un mail à rick <AT> gnous <dot> eu.

- -

Le projet

- -

Ce site est conçu pour réunir des liens de manière efficace afin de retrouver ou de stocker facilement une url.

-

- Il est codé uniquement en HTML et CSS pour le frontend et Python, avec Flask est utilisé pour le backend. Afin de pouvoir télécharger simplement ce site et de pouvoir le lancer sur son PC en local sans avoir à installer Python, une version statique est disponible ici; vous pouvez retrouver les fichiers dans le dossier lite du git. - Il est conçu afin de pouvoir durer 10 ans (du moins son frontend). -

- -

Contributeurs

- -

Projet débuté par Rick. Merci à Romain de tester le site pour trouver les failles de sécurité et de contribuer au code.

- -

Licence et autres

- -

Ce site est sous licence GPL3.0 or later et son code source est disponible sur le git de Gnous. Il est aux normes du W3C.

-
- licence GPL3 or Later - bage de validation html5 -
- - diff --git a/lite/autres.html b/lite/autres.html deleted file mode 100644 index ac08ab9..0000000 --- a/lite/autres.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - Autre - - - - -
- -
-
-
-

- t -

-

- - http://t.co - -

-
-

-

-
- - diff --git a/lite/img/html5-validator-badge.svg b/lite/img/html5-validator-badge.svg deleted file mode 100644 index 4294493..0000000 --- a/lite/img/html5-validator-badge.svg +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lite/img/licence.svg b/lite/img/licence.svg deleted file mode 100644 index a62fdac..0000000 --- a/lite/img/licence.svg +++ /dev/null @@ -1,315 +0,0 @@ - - - - - GPLv3 or Later - - - - image/svg+xml - - GPLv3 or Later - 2018-11-26 - - - Aryeom Han - - - - - Creative Commons by-sa - - - - - GPLv3 or Later logo made by Aryeom Han for the Free Software Foundation 2019 fundraising. -About the author, see: https://film.zemarmot.net/ - - - LILA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lite/index.html b/lite/index.html deleted file mode 100644 index 86b2cfe..0000000 --- a/lite/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - Partage de liens - - - -
- - - - diff --git a/lite/informatique.html b/lite/informatique.html deleted file mode 100644 index ea35b1d..0000000 --- a/lite/informatique.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - Informatique - - - - -
- -
-
- - diff --git a/lite/musique.html b/lite/musique.html deleted file mode 100644 index 8ac178e..0000000 --- a/lite/musique.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - Musique - - - - -
- -
-
- - diff --git a/lite/styles/apropos.css b/lite/styles/apropos.css deleted file mode 100644 index 9f3cbe0..0000000 --- a/lite/styles/apropos.css +++ /dev/null @@ -1,5 +0,0 @@ -img { - width: 150px; - height: auto; - margin-right: 50px; -} \ No newline at end of file diff --git a/lite/styles/base.css b/lite/styles/base.css deleted file mode 100644 index 95bdf84..0000000 --- a/lite/styles/base.css +++ /dev/null @@ -1,48 +0,0 @@ -body { - background-color: black; - color: white; -} - -#menu { - display: flex; -} - -#menu h1 { - margin: 10px; - margin-right: 25%; -} - -header { - width: 100%; - margin: 10px; - display: flex; - justify-content: space-around; -} - -header a { - text-align: center; - color: white; - text-decoration: none; - margin-right: 25%; - padding: 10px; - white-space: nowrap; -} - -header a:hover { - background-color: white; - color: black; -} - -#select { - background-color: grey; -} - -#select:hover { - background-color: grey; - color: white; -} - -#lienAccueil { - text-decoration: none; - color: white; -} \ No newline at end of file diff --git a/lite/styles/index.css b/lite/styles/index.css deleted file mode 100644 index bd5299f..0000000 --- a/lite/styles/index.css +++ /dev/null @@ -1,31 +0,0 @@ -#categories ul { - list-style-type: none; - display: flex; - justify-content:space-around; -} - -.elem { - margin: 10px; - padding: 5px; - padding-top: 2px; - background-color: darkslategrey; -} - -.elem a { - color: white; - font-weight: bolder; -} - -.elem ul { - list-style-type: none; - margin: 0; - padding: 0; - display: flex; - justify-content: start; -} - -.elem li { - margin-right: 5px; - padding: 5px; - background-color: dimgray; -} \ No newline at end of file diff --git a/static/autres.html b/static/autres.html deleted file mode 100644 index debd60f..0000000 --- a/static/autres.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - Autre - - - - -
- -
-
- - diff --git a/static/index.html b/static/index.html deleted file mode 100644 index d8dfc09..0000000 --- a/static/index.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - Partage de liens - - - -
- -
-

Rafraichissez la page pour voir les derniers liens ajoutés.

-
- - - - diff --git a/static/informatique.html b/static/informatique.html deleted file mode 100644 index ea35b1d..0000000 --- a/static/informatique.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - Informatique - - - - -
- -
-
- - diff --git a/static/musique.html b/static/musique.html deleted file mode 100644 index 8ac178e..0000000 --- a/static/musique.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - Musique - - - - -
- -
-
- - diff --git a/templates/index.html b/templates/index.html index a8c02c3..cb29ad2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,12 +10,29 @@ +
+ +
+

Rafraichissez la page pour voir les derniers liens ajoutés.


- + {% for lien in listeLiens %} +
+

{{lien.titre}}

+

{{lien.url}}

+
+

{{lien.desc}}

+
+ {% endfor %}