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"
rusqlite = {version = "0.28.0", features=["bundled"]}
lazy_static = "1.4.0"
mongodb = "2.3.1"

@ -8,6 +8,9 @@ pub struct Arguments {
/// Port to listen to
#[arg(short, long, default_value_t = 8081)]
pub port: u16,
/// root of the url ending and starting with /
#[arg(short, long, default_value_t = String::from("/"))]
pub root: String,
}
impl Arguments {
@ -22,7 +25,8 @@ impl Arguments {
#[derive(Clone)]
pub struct AppData {
pub name: String,
pub root: String,
pub db_url: 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")]
pub struct PageTemplate {
pub name: String,
pub root: String,
}
#[get("/")]
async fn index(data: web::Data<AppData>) -> impl Responder {
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 port = args.port;
let root = args.root;
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 || {

@ -9,12 +9,13 @@ use askama_actix::Template;
use askama_actix::TemplateToResponse;
use crate::commons::AppData;
use crate::database::DatabaseConnection;
//use crate::database::DatabaseConnection;
#[derive(Template)]
#[template(path = "page.html")]
pub struct PageTemplate {
pub name: String,
pub root: String,
pub md: String,
pub init: String,
}
@ -23,13 +24,14 @@ pub struct PageTemplate {
async fn page(path: web::Path<(String,)>, data: web::Data<AppData>) -> impl Responder {
let pagename = &path.0;
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 md = match fs::read_to_string(filename) {
Ok(txt) => txt,
Err(_) => String::from("# Nouvelle page"),
};
let init = String::from("init();");
PageTemplate { name, md, init }.to_response()
PageTemplate { name, root, md, init }.to_response()
}
#[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';
function timeoutSave() {
@ -85,7 +85,9 @@ function onkeydown(e) {
}
function onkeypress(e) {
if (e.key == 'Escape') {
if (e.key !== 'Escape') {
return true;
}
e.preventDefault();
document.getElementById('mdnotes').blur();
if (saveButton.disabled == false) {
@ -93,13 +95,11 @@ function onkeypress(e) {
}
return false;
}
if (e.key == 'Enter') {
}
}
function onkeyup(e) {
if (e.key == 'Escape') {
if (e.key !== 'Escape') {
return true;
}
e.preventDefault();
document.getElementById('mdnotes').blur();
if (saveButton.disabled == false) {
@ -107,7 +107,6 @@ function onkeyup(e) {
}
return false;
}
}
function onpaste(e) {
e.preventDefault();

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

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

@ -8,8 +8,8 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>{{name}}</title>
<link rel="stylesheet" href="/static/mdnotes.css">
<script type="module" src="/static/modules/mdnotes.js"></script>
<link rel="stylesheet" href="{{ root|safe }}static/cheezenotes.css">
<script type="module" src="{{ root|safe }}static/modules/cheezenotes.js"></script>
</head>
<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>
@ -17,7 +17,7 @@
<div id="mdnotes" class="mdnotes" contenteditable="true" spellcheck="false"></div>
<script type="module">
import { init } from '/static/modules/mdnotes.js';
import { init } from '{{ root|safe }}static/modules/cheezenotes.js';
{{ init|safe }}
</script>
</body>

Loading…
Cancel
Save