ajout d'une racine paramétrable pour l'url

pull/13/head
Nicolas Sanchez 3 years ago
parent 6a397234c5
commit e16c34d323

917
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -22,4 +22,6 @@ git2 = "0.16.0"
regex = "1" regex = "1"
rusqlite = {version = "0.28.0", features=["bundled"]} rusqlite = {version = "0.28.0", features=["bundled"]}
lazy_static = "1.4.0" lazy_static = "1.4.0"
mongodb = "2.3.1"

@ -8,6 +8,9 @@ pub struct Arguments {
/// Port to listen to /// Port to listen to
#[arg(short, long, default_value_t = 8081)] #[arg(short, long, default_value_t = 8081)]
pub port: u16, pub port: u16,
/// root of the url ending and starting with /
#[arg(short, long, default_value_t = String::from("/"))]
pub root: String,
} }
impl Arguments { impl Arguments {
@ -22,7 +25,8 @@ impl Arguments {
#[derive(Clone)] #[derive(Clone)]
pub struct AppData { pub struct AppData {
pub name: String, pub name: String,
pub root: String,
pub db_url: String, pub db_url: String,
pub db_user: String, pub db_user: String,
pub db_passwd: String, pub db_password: String,
} }

@ -10,10 +10,12 @@ use crate::commons::AppData;
#[template(path = "index.html")] #[template(path = "index.html")]
pub struct PageTemplate { pub struct PageTemplate {
pub name: String, pub name: String,
pub root: String,
} }
#[get("/")] #[get("/")]
async fn index(data: web::Data<AppData>) -> impl Responder { async fn index(data: web::Data<AppData>) -> impl Responder {
let name = data.name.to_owned(); let name = data.name.to_owned();
PageTemplate { name }.to_response() let root = data.root.to_owned();
PageTemplate { name, root }.to_response()
} }

@ -11,9 +11,14 @@ async fn main() -> std::io::Result<()> {
let ip = args.ip; let ip = args.ip;
let port = args.port; let port = args.port;
let root = args.root;
let appdata = AppData { let appdata = AppData {
name: String::from("MdNotes"), name: String::from("CheezeNotes"),
root,
db_url: String::from(""),
db_user: String::from(""),
db_password: String::from(""),
}; };
HttpServer::new(move || { HttpServer::new(move || {

@ -9,12 +9,13 @@ use askama_actix::Template;
use askama_actix::TemplateToResponse; use askama_actix::TemplateToResponse;
use crate::commons::AppData; use crate::commons::AppData;
use crate::database::DatabaseConnection; //use crate::database::DatabaseConnection;
#[derive(Template)] #[derive(Template)]
#[template(path = "page.html")] #[template(path = "page.html")]
pub struct PageTemplate { pub struct PageTemplate {
pub name: String, pub name: String,
pub root: String,
pub md: String, pub md: String,
pub init: String, pub init: String,
} }
@ -23,13 +24,14 @@ pub struct PageTemplate {
async fn page(path: web::Path<(String,)>, data: web::Data<AppData>) -> impl Responder { async fn page(path: web::Path<(String,)>, data: web::Data<AppData>) -> impl Responder {
let pagename = &path.0; let pagename = &path.0;
let name = data.name.to_owned() + " " + pagename.as_str(); let name = data.name.to_owned() + " " + pagename.as_str();
let root = data.root.to_owned();
let filename = String::from("pages/") + pagename.as_str() + ".md"; let filename = String::from("pages/") + pagename.as_str() + ".md";
let md = match fs::read_to_string(filename) { let md = match fs::read_to_string(filename) {
Ok(txt) => txt, Ok(txt) => txt,
Err(_) => String::from("# Nouvelle page"), Err(_) => String::from("# Nouvelle page"),
}; };
let init = String::from("init();"); let init = String::from("init();");
PageTemplate { name, md, init }.to_response() PageTemplate { name, root, md, init }.to_response()
} }
#[put("/page/{page}")] #[put("/page/{page}")]

@ -1,4 +1,4 @@
import { getStartPositionInLine, setStartPositionInLine } from './position.js'; import { getStartPositionInLine, setStartPositionInLine } from './caret.js';
import { formatLine, load, save, formatTable, redrawTables, appendData, dpwidth } from './md.js'; import { formatLine, load, save, formatTable, redrawTables, appendData, dpwidth } from './md.js';
function timeoutSave() { function timeoutSave() {
@ -85,28 +85,27 @@ function onkeydown(e) {
} }
function onkeypress(e) { function onkeypress(e) {
if (e.key == 'Escape') { if (e.key !== 'Escape') {
return true;
}
e.preventDefault(); e.preventDefault();
document.getElementById('mdnotes').blur(); document.getElementById('mdnotes').blur();
if (saveButton.disabled == false) { if (saveButton.disabled == false) {
onsave(); onsave();
} }
return false; return false;
}
if (e.key == 'Enter') {
}
} }
function onkeyup(e) { function onkeyup(e) {
if (e.key == 'Escape') { if (e.key !== 'Escape') {
return true;
}
e.preventDefault(); e.preventDefault();
document.getElementById('mdnotes').blur(); document.getElementById('mdnotes').blur();
if (saveButton.disabled == false) { if (saveButton.disabled == false) {
onsave(); onsave();
} }
return false; return false;
}
} }
function onpaste(e) { function onpaste(e) {

@ -1,4 +1,4 @@
import { getStartPositionInLine, setStartPositionInLine } from "./position.js"; import { getStartPositionInLine, setStartPositionInLine } from "./caret.js";
function load(textarea, div) { function load(textarea, div) {
div.innerHTML = ''; div.innerHTML = '';

@ -8,7 +8,7 @@
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>{{name}}</title> <title>{{name}}</title>
<link rel="stylesheet" href="../static/mdnotes.css"> <link rel="stylesheet" href="{{ root|safe }}static/cheezenotes.css">
</head> </head>
<body> <body>
<h1></h1> <h1></h1>

@ -8,8 +8,8 @@
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>{{name}}</title> <title>{{name}}</title>
<link rel="stylesheet" href="/static/mdnotes.css"> <link rel="stylesheet" href="{{ root|safe }}static/cheezenotes.css">
<script type="module" src="/static/modules/mdnotes.js"></script> <script type="module" src="{{ root|safe }}static/modules/cheezenotes.js"></script>
</head> </head>
<body> <body>
<div id="buttons"><button id="saveButton">💾</button> <input type="checkbox" id="taButton" /><label id="taButtonLabel" for="taButton">📋</label> <input type="checkbox" id="lockButton" /><label id="lockButtonLabel" for="lockButton">&#128065</label></div> <div id="buttons"><button id="saveButton">💾</button> <input type="checkbox" id="taButton" /><label id="taButtonLabel" for="taButton">📋</label> <input type="checkbox" id="lockButton" /><label id="lockButtonLabel" for="lockButton">&#128065</label></div>
@ -17,7 +17,7 @@
<div id="mdnotes" class="mdnotes" contenteditable="true" spellcheck="false"></div> <div id="mdnotes" class="mdnotes" contenteditable="true" spellcheck="false"></div>
<script type="module"> <script type="module">
import { init } from '/static/modules/mdnotes.js'; import { init } from '{{ root|safe }}static/modules/cheezenotes.js';
{{ init|safe }} {{ init|safe }}
</script> </script>
</body> </body>

Loading…
Cancel
Save