⚡️ Mejora rendimiento del renderizado de páginas
This commit is contained in:
parent
cffffe02d6
commit
8a184c38b6
6 changed files with 22 additions and 109 deletions
|
|
@ -96,7 +96,6 @@ async fn mdbook_page(
|
||||||
.with_assets(AssetsOp::AddJavaScript(JavaScript::from(
|
.with_assets(AssetsOp::AddJavaScript(JavaScript::from(
|
||||||
"/mdbook/navigators.js",
|
"/mdbook/navigators.js",
|
||||||
)))
|
)))
|
||||||
.with_body_skip_to("mdbook")
|
|
||||||
.with_component(Html::with(html! {
|
.with_component(Html::with(html! {
|
||||||
div id="mdbook" {
|
div id="mdbook" {
|
||||||
(PreEscaped(&html[beginning..]))
|
(PreEscaped(&html[beginning..]))
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,3 @@ pub use after_render_component::*;
|
||||||
|
|
||||||
mod render_component;
|
mod render_component;
|
||||||
pub use render_component::*;
|
pub use render_component::*;
|
||||||
|
|
||||||
mod before_render_page_body;
|
|
||||||
pub use before_render_page_body::*;
|
|
||||||
|
|
||||||
mod after_render_page_body;
|
|
||||||
pub use after_render_page_body::*;
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use crate::base::action::FnActionWithPage;
|
|
||||||
|
|
||||||
pub struct AfterRenderBody {
|
|
||||||
f: FnActionWithPage,
|
|
||||||
theme_type_id: Option<UniqueId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTrait for AfterRenderBody {
|
|
||||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
|
||||||
self.theme_type_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AfterRenderBody {
|
|
||||||
pub fn new(theme: ThemeRef, f: FnActionWithPage) -> Self {
|
|
||||||
AfterRenderBody {
|
|
||||||
f,
|
|
||||||
theme_type_id: Some(theme.type_id()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
#[allow(clippy::inline_always)]
|
|
||||||
pub(crate) fn dispatch(page: &mut Page) {
|
|
||||||
dispatch_actions(
|
|
||||||
&ActionKey::new(
|
|
||||||
UniqueId::of::<Self>(),
|
|
||||||
Some(page.context().theme().type_id()),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
|action: &Self| (action.f)(page),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use crate::base::action::FnActionWithPage;
|
|
||||||
|
|
||||||
pub struct BeforeRenderBody {
|
|
||||||
f: FnActionWithPage,
|
|
||||||
theme_type_id: Option<UniqueId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTrait for BeforeRenderBody {
|
|
||||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
|
||||||
self.theme_type_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BeforeRenderBody {
|
|
||||||
pub fn new(theme: ThemeRef, f: FnActionWithPage) -> Self {
|
|
||||||
BeforeRenderBody {
|
|
||||||
f,
|
|
||||||
theme_type_id: Some(theme.type_id()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
#[allow(clippy::inline_always)]
|
|
||||||
pub(crate) fn dispatch(page: &mut Page) {
|
|
||||||
dispatch_actions(
|
|
||||||
&ActionKey::new(
|
|
||||||
UniqueId::of::<Self>(),
|
|
||||||
Some(page.context().theme().type_id()),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
|action: &Self| (action.f)(page),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,7 +12,21 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
||||||
vec![("content", L10n::l("content"))]
|
vec![("content", L10n::l("content"))]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_head(&self, page: &mut Page) -> Markup {
|
#[allow(unused_variables)]
|
||||||
|
fn before_render_page_body(&self, page: &mut Page) {}
|
||||||
|
|
||||||
|
fn render_page_body(&self, page: &mut Page) -> Markup {
|
||||||
|
html! {
|
||||||
|
body id=[page.body_id().get()] class=[page.body_classes().get()] {
|
||||||
|
(page.context().render_region("content"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
fn after_render_page_body(&self, page: &mut Page) {}
|
||||||
|
|
||||||
|
fn render_page_head(&self, page: &mut Page) -> Markup {
|
||||||
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
|
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
|
||||||
html! {
|
html! {
|
||||||
head {
|
head {
|
||||||
|
|
@ -42,12 +56,4 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_body(&self, page: &mut Page) -> Markup {
|
|
||||||
html! {
|
|
||||||
body id=[page.body_id().get()] class=[page.body_classes().get()] {
|
|
||||||
(page.context().render_region("content"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ pub struct Page {
|
||||||
context : Context,
|
context : Context,
|
||||||
body_id : OptionId,
|
body_id : OptionId,
|
||||||
body_classes: OptionClasses,
|
body_classes: OptionClasses,
|
||||||
body_skip_to: OptionId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page {
|
impl Page {
|
||||||
|
|
@ -37,7 +36,6 @@ impl Page {
|
||||||
context : Context::new(request),
|
context : Context::new(request),
|
||||||
body_id : OptionId::default(),
|
body_id : OptionId::default(),
|
||||||
body_classes: OptionClasses::default(),
|
body_classes: OptionClasses::default(),
|
||||||
body_skip_to: OptionId::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,12 +83,6 @@ impl Page {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_body_skip_to(&mut self, id: impl Into<String>) -> &mut Self {
|
|
||||||
self.body_skip_to.alter_value(id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_theme(&mut self, theme: &'static str) -> &mut Self {
|
pub fn alter_theme(&mut self, theme: &'static str) -> &mut Self {
|
||||||
self.context.alter_assets(AssetsOp::Theme(theme));
|
self.context.alter_assets(AssetsOp::Theme(theme));
|
||||||
|
|
@ -155,32 +147,28 @@ impl Page {
|
||||||
&self.body_classes
|
&self.body_classes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body_skip_to(&self) -> &OptionId {
|
|
||||||
&self.body_skip_to
|
|
||||||
}
|
|
||||||
|
|
||||||
// Page RENDER.
|
// Page RENDER.
|
||||||
|
|
||||||
pub fn render(&mut self) -> ResultPage<Markup, ErrorPage> {
|
pub fn render(&mut self) -> ResultPage<Markup, ErrorPage> {
|
||||||
// Acciones específicas del diseño antes de renderizar el <body>.
|
// Acciones específicas del tema antes de renderizar el <body>.
|
||||||
action::theme::BeforeRenderBody::dispatch(self);
|
self.context.theme().before_render_page_body(self);
|
||||||
|
|
||||||
// Acciones de los paquetes antes de renderizar el <body>.
|
// Acciones de los paquetes antes de renderizar el <body>.
|
||||||
action::page::BeforeRenderBody::dispatch(self);
|
action::page::BeforeRenderBody::dispatch(self);
|
||||||
|
|
||||||
// Renderiza el <body>.
|
// Renderiza el <body>.
|
||||||
let body = self.context.theme().render_body(self);
|
let body = self.context.theme().render_page_body(self);
|
||||||
|
|
||||||
// Acciones específicas del diseño después de renderizar el <body>.
|
// Acciones específicas del tema después de renderizar el <body>.
|
||||||
action::theme::AfterRenderBody::dispatch(self);
|
self.context.theme().after_render_page_body(self);
|
||||||
|
|
||||||
// Acciones de los paquetes después de renderizar el <body>.
|
// Acciones de los paquetes después de renderizar el <body>.
|
||||||
action::page::AfterRenderBody::dispatch(self);
|
action::page::AfterRenderBody::dispatch(self);
|
||||||
|
|
||||||
// Renderiza el <head>.
|
// Renderiza el <head>.
|
||||||
let head = self.context.theme().render_head(self);
|
let head = self.context.theme().render_page_head(self);
|
||||||
|
|
||||||
// Compone la página completa incluyendo los atributos de idioma y dirección del texto.
|
// Compone la página incluyendo los atributos de idioma y dirección del texto.
|
||||||
let lang = &self.context.langid().language;
|
let lang = &self.context.langid().language;
|
||||||
let dir = match self.context.langid().character_direction() {
|
let dir = match self.context.langid().character_direction() {
|
||||||
CharacterDirection::LTR => "ltr",
|
CharacterDirection::LTR => "ltr",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue