Compare commits

..

3 Commits

Binary file not shown.

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cargo run -- --port 9090 --root https://vscode.cheeze.fr/proxy/9090/

@ -12,7 +12,7 @@ impl NormalizeName for String {
fn normalize_name(&self) -> String { fn normalize_name(&self) -> String {
let space_re = Regex::new(r"[\s_]+").unwrap(); 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); let mut str = unidecode(self);
str = space_re.replace_all(&str, "_").to_string(); str = space_re.replace_all(&str, "_").to_string();

@ -26,6 +26,7 @@ struct QueryParams {
pub data: Option<String>, pub data: Option<String>,
pub fromDomain: Option<String>, pub fromDomain: Option<String>,
pub fromPage: Option<String>, pub fromPage: Option<String>,
pub libelle: Option<String>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -53,12 +54,17 @@ fn new_page_text(
page_name: String, page_name: String,
domain_from: &Option<String>, domain_from: &Option<String>,
page_from: &Option<String>, page_from: &Option<String>,
libelle: &Option<String>,
) -> String { ) -> String {
let mut retour = String::from(""); let mut retour = String::from("");
if let (Some(domain_f), Some(page_f)) = (domain_from, page_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( 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()); db::get_page_by_name(&data.db_pool, domain.to_owned(), page_name.to_owned());
let page_datas = fut_page_datas.await.unwrap(); let page_datas = fut_page_datas.await.unwrap();
match page_datas.first() { match page_datas.first() {
None => new_page_text(page_name, &params.fromDomain, &params.fromPage), None => new_page_text(page_name, &params.fromDomain, &params.fromPage, &params.libelle),
Some(dat) => (*dat.page_text).to_string(), Some(dat) => (*dat.page_text).to_string(),
} }
} }
#[get("/{domain}/{page}")] #[get("/{domain}:{page}")]
async fn page( async fn page(
path: web::Path<(String, String)>, path: web::Path<(String, String)>,
data: web::Data<AppData>, data: web::Data<AppData>,
@ -99,7 +105,7 @@ async fn page(
let app_name = data.app_name.to_owned() + " - " + page_name.as_str(); let app_name = data.app_name.to_owned() + " - " + page_name.as_str();
let base_url = data.base_url.to_owned(); let base_url = data.base_url.to_owned();
//let init = String::from("init();"); //let init = String::from("init();");
let init = format!("init({:?}, {:?});", domain, page_name); let init = format!("init({:?}, {:?}, {:?});", domain, base_url, page_name);
PageTemplate { PageTemplate {
app_name, app_name,
base_url, base_url,
@ -109,7 +115,7 @@ async fn page(
.to_response() .to_response()
} }
#[put("/{domain}/{page}")] #[put("/{domain}:{page}")]
async fn save_page( async fn save_page(
body: String, body: String,
path: web::Path<(String, String)>, path: web::Path<(String, String)>,

@ -40,7 +40,12 @@ body {
p.domain { p.domain {
padding-left: 2rem; padding-left: 2rem;
font-size: 2rem; font-size: 1.5rem;
}
p.page {
padding-left: 2rem;
font-size: 1.5rem;
} }
div#content { div#content {

@ -156,6 +156,10 @@ function onedit(e) {
let line = ret[0]; let line = ret[0];
let position = ret[1]; let position = ret[1];
if (! line) {
return;
}
if (line.innerText == '\n') { if (line.innerText == '\n') {
line.className = 'cheezenotes_line'; line.className = 'cheezenotes_line';
line.classList.add('body'); 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'); let cheezenotes = document.getElementById('cheezenotes');
window.domain = domain; window.domain = domain;
window.page = page; window.page = page;
window.base_url = base_url;
dpwidth(cheezenotes); dpwidth(cheezenotes);

@ -1,11 +1,12 @@
import { saveSelection, loadSelection } from "./caret.js"; import { saveSelection, loadSelection } from "./caret.js";
import { normalizePagename } from "./tools.js"; import { normalizeName } from "./tools.js";
function setEditable() { function setEditable() {
let editModeButton = document.getElementById('editModeButton'); let editModeButton = document.getElementById('editModeButton');
let cheezenotes = document.getElementById('cheezenotes'); let cheezenotes = document.getElementById('cheezenotes');
if (editModeButton.classList.contains('buttonoff')) { if (editModeButton.classList.contains('buttonoff')) {
cheezenotes.contentEditable = false; cheezenotes.contentEditable = false;
window.getSelection().removeAllRanges();
} else { } else {
cheezenotes.contentEditable = true; cheezenotes.contentEditable = true;
} }
@ -94,6 +95,7 @@ function onlinkin(e) {
let link = e.currentTarget; let link = e.currentTarget;
if (document.getElementById('cheezenotes') !== document.activeElement) { if (document.getElementById('cheezenotes') !== document.activeElement) {
document.getElementById('cheezenotes').contentEditable = false; document.getElementById('cheezenotes').contentEditable = false;
window.getSelection().removeAllRanges();
} }
} }
@ -103,10 +105,11 @@ function onlink(e) {
e.preventDefault(); e.preventDefault();
setEditable(); setEditable();
let link = e.currentTarget; let link = e.currentTarget;
if (link.host !== document.location.host) { let datahref = link.getAttribute('data-href');
if (datahref.includes('/')) {
open(link.href); open(link.href);
} else { } 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'); let ta = document.getElementById('ta');
response.text().then((data) => { response.text().then((data) => {
let content = document.getElementById('content'); let content = document.getElementById('content');
@ -114,9 +117,9 @@ function onlink(e) {
let top = content.scrollTop; let top = content.scrollTop;
window.history.replaceState({ top: top, left: left }, ""); window.history.replaceState({ top: top, left: left }, "");
window.history.pushState({}, "", link.href); window.history.pushState({}, "", link.href);
document.title = 'CheezeNotes - ' + link.getAttribute('data-href'); document.title = 'CheezeNotes - ' + datahref;
ta.value = data; ta.value = data;
let url = link.getAttribute('data-href').split('/'); let url = datahref.split(':');
let page = url[0]; let page = url[0];
let domain = window.domain; let domain = window.domain;
if (url.length == 3) { 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) { function oncheckbox(e) {
/*let cheezenotes = document.getElementById('cheezenotes');
cheezenotes.contentEditable = false;
window.getSelection().removeAllRanges();*/
console.log("oncheckbox");
let cb = e.currentTarget; let cb = e.currentTarget;
let line = cb.parentNode; let line = cb.parentNode;
let text = line.innerText; let text = line.innerText;
@ -270,6 +285,7 @@ function formatLine(line) {
for (let i = 0; i < checkboxes.length; i++) { for (let i = 0; i < checkboxes.length; i++) {
let checkbox = checkboxes[i]; let checkbox = checkboxes[i];
checkbox.addEventListener('mouseover', onlinkin); checkbox.addEventListener('mouseover', onlinkin);
checkbox.addEventListener('click', onclickcheckbox);
checkbox.addEventListener('change', oncheckbox); checkbox.addEventListener('change', oncheckbox);
checkbox.addEventListener('mouseout', onlinkout); checkbox.addEventListener('mouseout', onlinkout);
} }
@ -581,16 +597,26 @@ function formatLink(link) {
if (href == '') { if (href == '') {
href = libelle; href = libelle;
} }
if (href.match(/^[^\:\/]+\/.*$/)) { let datahref = href;
href = '/' + 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 == '') { if (libelle == '') {
return '<span class="token">[](</span><a class="link" data-href="' + href + '" href="' + href + '">' + url + '</a><span class="token">)</span>'; return '<span class="token">[](</span><a class="link" data-href="' + datahref + '" href="' + href + '">' + url + '</a><span class="token">)</span>';
} else { } else {
if (libelle.startsWith('!')) { if (libelle.startsWith('!')) {
return '<span class="token">[' + libelle + '</span><img style="vertical-align: top; max-height: 1rem;" class="image" src="' + href + '" title="' + libelle.substring(1) + '" /><span class="token">](' + url + ')</span>'; return '<span class="token">[' + libelle + '</span><img style="vertical-align: top; max-height: 1rem;" class="image" src="' + href + '" title="' + libelle.substring(1) + '" /><span class="token">](' + url + ')</span>';
} else { } else {
return '<span class="token">[</span><a class="link" data-href="' + href + '" href="' + href + '">' + libelle + '</a><span class="token">](' + url + ')</span>'; return '<span class="token">[</span><a class="link" data-href="' + datahref + '" href="' + href + '">' + libelle + '</a><span class="token">](' + url + ')</span>';
} }
} }
} }

@ -1,6 +1,6 @@
function normalizeName(pagename) { function normalizeName(name) {
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, "_"); 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 }; export { normalizeName };

@ -12,8 +12,9 @@
</head> </head>
<body> <body>
<h1>{{app_name}} {{ domain }}</h1> <h1>{{app_name}} {{ domain }}</h1>
<h2>Liste des pages</h2>
{% for page in pages %} {% for page in pages %}
<p class="page"><a href="{{ base_url|safe }}{{ page.domain }}/{{ page.page_name }}">{{ page.page_name }}</a></p> <p class="page"><a href="{{ base_url|safe }}{{ page.domain }}:{{ page.page_name }}">{{ page.page_name }}</a></p>
{% endfor %} {% endfor %}
</body> </body>
</html> </html>

@ -12,6 +12,7 @@
</head> </head>
<body> <body>
<h1>{{app_name}}</h1> <h1>{{app_name}}</h1>
<h2>Liste des domaines</h2>
{% for domain in domains %} {% for domain in domains %}
<p class="domain"><a href="{{ base_url|safe }}{{ domain.domain }}">{{ domain.domain_name }}</a></p> <p class="domain"><a href="{{ base_url|safe }}{{ domain.domain }}">{{ domain.domain_name }}</a></p>
{% endfor %} {% endfor %}

Loading…
Cancel
Save