Retoca y depura info capturada de página [mdbook]
This commit is contained in:
parent
3297c24082
commit
33c3262426
2 changed files with 58 additions and 23 deletions
7
website/doc/theme/index.hbs
vendored
7
website/doc/theme/index.hbs
vendored
|
|
@ -1,9 +1,10 @@
|
||||||
<!-- Lang: "{{ language }}" -->
|
<!-- Lang: {{ language }} -->
|
||||||
<!-- Title: "{{ title }}" -->
|
<!-- Title: {{ title }} -->
|
||||||
<!-- Description: "{{ description }}" -->
|
|
||||||
<!-- Print: {{#if print_enable}}enabled{{else}}disabled{{/if}} -->
|
<!-- Print: {{#if print_enable}}enabled{{else}}disabled{{/if}} -->
|
||||||
<!-- MathJax: {{#if mathjax_support}}supported{{else}}unsupported{{/if}} -->
|
<!-- MathJax: {{#if mathjax_support}}supported{{else}}unsupported{{/if}} -->
|
||||||
|
|
||||||
|
<!-- mdBook -->
|
||||||
|
|
||||||
<!-- Provide site root to javascript -->
|
<!-- Provide site root to javascript -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var path_to_root = "{{ path_to_root }}";
|
var path_to_root = "{{ path_to_root }}";
|
||||||
|
|
|
||||||
|
|
@ -35,45 +35,67 @@ async fn mdbook_page(request: app::HttpRequest) -> ResultPage<Markup, FatalError
|
||||||
|
|
||||||
if let Some(content) = MDBOOK.get(path) {
|
if let Some(content) = MDBOOK.get(path) {
|
||||||
if let Ok(html) = std::str::from_utf8(content.data) {
|
if let Ok(html) = std::str::from_utf8(content.data) {
|
||||||
let mut page = Page::new().with_title("Documentación");
|
|
||||||
page.context()
|
let _lang = extract("Lang", html);
|
||||||
.alter(InContextOp::AddMetadata("theme-color", "#ffffff"))
|
let title = match extract("Title", html) {
|
||||||
.alter(InContextOp::StyleSheet(
|
Some(title) => title,
|
||||||
|
_ => "Documentación",
|
||||||
|
};
|
||||||
|
let _print = match extract("Print", html) {
|
||||||
|
Some("enabled") => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
let _mathjax = match extract("MathJax", html) {
|
||||||
|
Some("supported") => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
let beginning = {
|
||||||
|
let separator = "<!-- mdBook -->";
|
||||||
|
match html.find(separator) {
|
||||||
|
Some(pos) => pos + separator.len(),
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Page::new()
|
||||||
|
.with_title(title)
|
||||||
|
.with_context(InContextOp::AddMetadata("theme-color", "#ffffff"))
|
||||||
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/variables.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/variables.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/general.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/general.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/chrome.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/css/chrome.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(
|
AssetsOp::<StyleSheet>::Add(
|
||||||
StyleSheet::located("/doc/css/print.css").for_media(TargetMedia::Print)
|
StyleSheet::located("/doc/css/print.css").for_media(TargetMedia::Print)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/FontAwesome/css/font-awesome.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/FontAwesome/css/font-awesome.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/fonts/fonts.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/fonts/fonts.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/highlight.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/highlight.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/tomorrow-night.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/tomorrow-night.css"))
|
||||||
))
|
))
|
||||||
.alter(InContextOp::StyleSheet(
|
.with_context(InContextOp::StyleSheet(
|
||||||
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/ayu-highlight.css"))
|
AssetsOp::<StyleSheet>::Add(StyleSheet::located("/doc/ayu-highlight.css"))
|
||||||
));
|
))
|
||||||
page.add_to(
|
.add_to(
|
||||||
"region-content",
|
"region-content",
|
||||||
Container::new()
|
Container::new()
|
||||||
.with_id("mdbook")
|
.with_id("mdbook")
|
||||||
.with_component(Html::with(html! { (PreEscaped(html)) }))
|
.with_component(Html::with(html! { (PreEscaped(&html[beginning..])) }))
|
||||||
)
|
)
|
||||||
.render()
|
.render()
|
||||||
} else {
|
} else {
|
||||||
Err(FatalError::NotFound)
|
Err(FatalError::NotFound)
|
||||||
}
|
}
|
||||||
|
|
@ -152,3 +174,15 @@ fn none_match(etag: Option<&app::http::header::EntityTag>, request: &app::HttpRe
|
||||||
None => true,
|
None => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract(attr: &'static str, from: &'static str) -> Option<&'static str> {
|
||||||
|
let search = concat_string!("<!-- ", attr, ":");
|
||||||
|
if let Some(ini) = from.find(&search) {
|
||||||
|
let ini = ini + search.len() + 1;
|
||||||
|
if let Some(end) = from[ini..].find("-->").map(|i| i + ini) {
|
||||||
|
let end = end - 1;
|
||||||
|
return Some(&from[ini..end]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue