diff --git a/db/db.sqlite3 b/db/db.sqlite3 index 26c43ca..e8f49a0 100644 Binary files a/db/db.sqlite3 and b/db/db.sqlite3 differ diff --git a/launch.bash b/launch.bash new file mode 100755 index 0000000..b294924 --- /dev/null +++ b/launch.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cargo run -- --port 9090 --root https://vscode.cheeze.fr/proxy/9090/ diff --git a/src/commons.rs b/src/commons.rs index 376bf6f..8faae1b 100644 --- a/src/commons.rs +++ b/src/commons.rs @@ -12,7 +12,7 @@ impl NormalizeName for String { fn normalize_name(&self) -> String { let space_re = Regex::new(r"[\s_]+").unwrap(); - let remove_re = Regex::new(r"[^a-z0-9_]").unwrap(); + let remove_re = Regex::new(r"[^a-z0-9_\-]").unwrap(); let mut str = unidecode(self); str = space_re.replace_all(&str, "_").to_string(); diff --git a/src/page.rs b/src/page.rs index 4e8582b..7d36ebb 100644 --- a/src/page.rs +++ b/src/page.rs @@ -26,6 +26,7 @@ struct QueryParams { pub data: Option, pub fromDomain: Option, pub fromPage: Option, + pub libelle: Option, } #[derive(Serialize, Deserialize)] @@ -53,12 +54,17 @@ fn new_page_text( page_name: String, domain_from: &Option, page_from: &Option, + libelle: &Option, ) -> String { let mut retour = String::from(""); if let (Some(domain_f), Some(page_f)) = (domain_from, page_from) { - retour = format!("[retour](/{}/{})\n", domain_f, page_f); + retour = format!("[retour]({}:{})\n", domain_f, page_f); } - retour + "# " + page_name.replace("_", " ").as_str() + let mut titre = page_name.replace("_", " "); + if let Some(lib) = libelle { + titre = lib.to_string(); + } + retour + "# " + titre.as_str() } async fn get_data( @@ -71,12 +77,12 @@ async fn get_data( db::get_page_by_name(&data.db_pool, domain.to_owned(), page_name.to_owned()); let page_datas = fut_page_datas.await.unwrap(); match page_datas.first() { - None => new_page_text(page_name, ¶ms.fromDomain, ¶ms.fromPage), + None => new_page_text(page_name, ¶ms.fromDomain, ¶ms.fromPage, ¶ms.libelle), Some(dat) => (*dat.page_text).to_string(), } } -#[get("/{domain}/{page}")] +#[get("/{domain}:{page}")] async fn page( path: web::Path<(String, String)>, data: web::Data, @@ -99,7 +105,7 @@ async fn page( let app_name = data.app_name.to_owned() + " - " + page_name.as_str(); let base_url = data.base_url.to_owned(); //let init = String::from("init();"); - let init = format!("init({:?}, {:?});", domain, page_name); + let init = format!("init({:?}, {:?}, {:?});", domain, base_url, page_name); PageTemplate { app_name, base_url, @@ -109,7 +115,7 @@ async fn page( .to_response() } -#[put("/{domain}/{page}")] +#[put("/{domain}:{page}")] async fn save_page( body: String, path: web::Path<(String, String)>, diff --git a/static/cheezenotes.css b/static/cheezenotes.css index c42eac4..d347b29 100644 --- a/static/cheezenotes.css +++ b/static/cheezenotes.css @@ -40,7 +40,12 @@ body { p.domain { padding-left: 2rem; - font-size: 2rem; + font-size: 1.5rem; +} + +p.page { + padding-left: 2rem; + font-size: 1.5rem; } div#content { diff --git a/static/modules/cheezenotes.js b/static/modules/cheezenotes.js index 973c626..34610f3 100644 --- a/static/modules/cheezenotes.js +++ b/static/modules/cheezenotes.js @@ -156,6 +156,10 @@ function onedit(e) { let line = ret[0]; let position = ret[1]; + if (! line) { + return; + } + if (line.innerText == '\n') { line.className = 'cheezenotes_line'; line.classList.add('body'); @@ -360,10 +364,11 @@ function onparentbutton(e) { } -function init(domain, page) { +function init(domain, base_url, page) { let cheezenotes = document.getElementById('cheezenotes'); window.domain = domain; window.page = page; + window.base_url = base_url; dpwidth(cheezenotes); diff --git a/static/modules/md.js b/static/modules/md.js index f8fcae6..8c63285 100644 --- a/static/modules/md.js +++ b/static/modules/md.js @@ -1,11 +1,12 @@ import { saveSelection, loadSelection } from "./caret.js"; -import { normalizePagename } from "./tools.js"; +import { normalizeName } from "./tools.js"; function setEditable() { let editModeButton = document.getElementById('editModeButton'); let cheezenotes = document.getElementById('cheezenotes'); if (editModeButton.classList.contains('buttonoff')) { cheezenotes.contentEditable = false; + window.getSelection().removeAllRanges(); } else { cheezenotes.contentEditable = true; } @@ -94,6 +95,7 @@ function onlinkin(e) { let link = e.currentTarget; if (document.getElementById('cheezenotes') !== document.activeElement) { document.getElementById('cheezenotes').contentEditable = false; + window.getSelection().removeAllRanges(); } } @@ -103,10 +105,11 @@ function onlink(e) { e.preventDefault(); setEditable(); let link = e.currentTarget; - if (link.host !== document.location.host) { + let datahref = link.getAttribute('data-href'); + if (datahref.includes('/')) { open(link.href); } else { - fetch(link.href + '?data=&fromDomain=' + window.domain + '&fromPage=' + window.page).then((response) => { + fetch(link.href + '?data=&fromDomain=' + window.domain + '&fromPage=' + window.page + '&libelle=' + link.innerText).then((response) => { let ta = document.getElementById('ta'); response.text().then((data) => { let content = document.getElementById('content'); @@ -114,9 +117,9 @@ function onlink(e) { let top = content.scrollTop; window.history.replaceState({ top: top, left: left }, ""); window.history.pushState({}, "", link.href); - document.title = 'CheezeNotes - ' + link.getAttribute('data-href'); + document.title = 'CheezeNotes - ' + datahref; ta.value = data; - let url = link.getAttribute('data-href').split('/'); + let url = datahref.split(':'); let page = url[0]; let domain = window.domain; if (url.length == 3) { @@ -145,7 +148,19 @@ function onlinkout(e) { } } +function onclickcheckbox(e) { + let cheezenotes = document.getElementById('cheezenotes'); + cheezenotes.contentEditable = false; + window.getSelection().removeAllRanges(); + console.log("onclickcheckbox"); +} + function oncheckbox(e) { + /*let cheezenotes = document.getElementById('cheezenotes'); + cheezenotes.contentEditable = false; + window.getSelection().removeAllRanges();*/ + console.log("oncheckbox"); + let cb = e.currentTarget; let line = cb.parentNode; let text = line.innerText; @@ -270,6 +285,7 @@ function formatLine(line) { for (let i = 0; i < checkboxes.length; i++) { let checkbox = checkboxes[i]; checkbox.addEventListener('mouseover', onlinkin); + checkbox.addEventListener('click', onclickcheckbox); checkbox.addEventListener('change', oncheckbox); checkbox.addEventListener('mouseout', onlinkout); } @@ -581,16 +597,26 @@ function formatLink(link) { if (href == '') { href = libelle; } - if (href.match(/^[^\:\/]+\/.*$/)) { - href = '/' + href; + let datahref = href; + + if (href.match(/\:\/\//)) { + datahref = href; + } else { + let dh = datahref.split(':'); + if (dh.length === 1) { + datahref = window.domain + ":" + datahref; + } + datahref = normalizeName(datahref); + href = window.base_url + datahref; } + if (libelle == '') { - return '[](' + url + ')'; + return '[](' + url + ')'; } else { if (libelle.startsWith('!')) { return '[' + libelle + '](' + url + ')'; } else { - return '[' + libelle + '](' + url + ')'; + return '[' + libelle + '](' + url + ')'; } } } diff --git a/static/modules/tools.js b/static/modules/tools.js index 4df069e..324a7c7 100644 --- a/static/modules/tools.js +++ b/static/modules/tools.js @@ -1,6 +1,6 @@ -function normalizeName(pagename) { - return str.normalize("NFKD").replace(/\p{Diacritic}/gu, "").toLowerCase().replace(/œ/g, "oe").replace(/æ/g, "ae").replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").replace(/_+/g, "_"); +function normalizeName(name) { + return name.normalize("NFKD").replace(/\p{Diacritic}/gu, "").toLowerCase().replace(/œ/g, "oe").replace(/æ/g, "ae").replace(/[\s_]+/g, "_").replace(/[^a-z0-9_\-:]/g, ""); } export { normalizeName }; \ No newline at end of file diff --git a/templates/domain.html b/templates/domain.html index f1c889f..63f0b8b 100644 --- a/templates/domain.html +++ b/templates/domain.html @@ -12,8 +12,9 @@

{{app_name}} {{ domain }}

+

Liste des pages

{% for page in pages %} -

{{ page.page_name }}

+

{{ page.page_name }}

{% endfor %} diff --git a/templates/index.html b/templates/index.html index c2448ee..dd4ac6e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,6 +12,7 @@

{{app_name}}

+

Liste des domaines

{% for domain in domains %}

{{ domain.domain_name }}

{% endfor %}