Internal link to another local document support
This commit is contained in:
parent
533d2c1044
commit
9053debd77
4 changed files with 18 additions and 6 deletions
|
@ -54,7 +54,7 @@ fn get_content(
|
|||
return None;
|
||||
}
|
||||
|
||||
read_file(format!("{cours_dir}/{filename}"), MType::Generic)
|
||||
read_file(format!("{cours_dir}/{filename}"), MType::Cours)
|
||||
}
|
||||
|
||||
fn build_page(info: &web::Query<PathRequest>, config: Config) -> String {
|
||||
|
|
|
@ -8,6 +8,7 @@ use ramhorns::Content;
|
|||
use std::fmt::Debug;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::utils::metadata::MType;
|
||||
|
||||
|
@ -21,7 +22,7 @@ pub struct File {
|
|||
}
|
||||
|
||||
/// Options used for parser and compiler MD --> HTML
|
||||
pub fn get_options() -> ComrakOptions {
|
||||
pub fn get_options(metadata_type: MType) -> ComrakOptions {
|
||||
comrak::Options {
|
||||
extension: comrak::ExtensionOptions::builder()
|
||||
.strikethrough(true)
|
||||
|
@ -37,6 +38,16 @@ pub fn get_options() -> ComrakOptions {
|
|||
.multiline_block_quotes(true)
|
||||
.math_dollars(true)
|
||||
.underline(true)
|
||||
.maybe_link_url_rewriter(match metadata_type {
|
||||
MType::Cours => Some(Arc::new(|url: &str| {
|
||||
if url.contains("://") {
|
||||
return String::from(url);
|
||||
}
|
||||
|
||||
format!("/cours?q={url}")
|
||||
})),
|
||||
_ => None,
|
||||
})
|
||||
.build(),
|
||||
parse: comrak::ParseOptions::builder()
|
||||
.smart(true)
|
||||
|
@ -134,7 +145,7 @@ fn fix_images_and_integration(
|
|||
if let Ok(file) = fs::read_to_string(&img_path) {
|
||||
let mime = mime_guess::from_path(&img_path).first_or_octet_stream();
|
||||
if recursive && mime == "text/markdown" {
|
||||
let mut options = get_options();
|
||||
let mut options = get_options(metadata_type);
|
||||
options.extension.footnotes = false;
|
||||
let data =
|
||||
read_md(&img_path, &file, metadata_type, Some(options), false);
|
||||
|
@ -174,7 +185,7 @@ pub fn read_md(
|
|||
) -> File {
|
||||
let arena = Arena::new();
|
||||
|
||||
let mut opt = options.map_or_else(get_options, |specific_opt| specific_opt);
|
||||
let mut opt = options.map_or_else(|| get_options(metadata_type), |specific_opt| specific_opt);
|
||||
let root = parse_document(&arena, raw_text, &opt);
|
||||
|
||||
// Find metadata
|
||||
|
|
|
@ -74,6 +74,7 @@ pub struct FileMetadataPortfolio {
|
|||
pub enum MType {
|
||||
Blog,
|
||||
Contact,
|
||||
Cours,
|
||||
Generic,
|
||||
Index,
|
||||
Portfolio,
|
||||
|
@ -140,7 +141,7 @@ pub fn get<'a>(root: &'a AstNode<'a>, mtype: MType) -> MFile {
|
|||
..MFile::default()
|
||||
}
|
||||
}
|
||||
MType::Generic => MFile {
|
||||
MType::Generic | MType::Cours => MFile {
|
||||
hardbreaks: deserialize_metadata(text),
|
||||
..MFile::default()
|
||||
},
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn get_posts(location: &str) -> Vec<Post> {
|
|||
|text| {
|
||||
let arena = Arena::new();
|
||||
|
||||
let options = get_options();
|
||||
let options = get_options(MType::Generic);
|
||||
let root = parse_document(&arena, &text, &options);
|
||||
let mut metadata = get(root, MType::Blog).blog.unwrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue