diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index b3ea6a0..5f0a58f 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -268,6 +268,10 @@ impl Section { pub fn to_serialized<'a>(&'a self, library: &'a Library) -> SerializingSection<'a> { SerializingSection::from_section(self, library) } + + pub fn to_serialized_basic<'a>(&'a self, library: &'a Library) -> SerializingSection<'a> { + SerializingSection::from_section_basic(self, Some(library)) + } } /// Used to create a default index section if there is no _index.md in the root content directory diff --git a/components/templates/src/global_fns.rs b/components/templates/src/global_fns.rs index 5b80c68..872ed98 100644 --- a/components/templates/src/global_fns.rs +++ b/components/templates/src/global_fns.rs @@ -75,11 +75,17 @@ pub fn make_get_page(library: &Library) -> GlobalFn { pub fn make_get_section(library: &Library) -> GlobalFn { let mut sections = HashMap::new(); + let mut sections_basic = HashMap::new(); for section in library.sections_values() { sections.insert( section.file.relative.clone(), to_value(library.get_section(§ion.file.path).unwrap().to_serialized(library)).unwrap(), ); + + sections_basic.insert( + section.file.relative.clone(), + to_value(library.get_section(§ion.file.path).unwrap().to_serialized_basic(library)).unwrap(), + ); } Box::new(move |args| -> Result { @@ -89,7 +95,19 @@ pub fn make_get_section(library: &Library) -> GlobalFn { "`get_section` requires a `path` argument with a string value" ); - match sections.get(&path) { + let metadata_only = args + .get("metadata_only") + .map_or(false, |c| { + from_value::(c.clone()).unwrap_or(false) + }); + + let container = if metadata_only { + §ions_basic + } else { + §ions + }; + + match container.get(&path) { Some(p) => Ok(p.clone()), None => Err(format!("Section `{}` not found.", path).into()) } diff --git a/docs/content/documentation/templates/overview.md b/docs/content/documentation/templates/overview.md index a9ab635..019d992 100644 --- a/docs/content/documentation/templates/overview.md +++ b/docs/content/documentation/templates/overview.md @@ -92,6 +92,12 @@ Takes a path to a `_index.md` file and returns the associated section {% set section = get_section(path="blog/_index.md") %} ``` +If you only need the metadata of the section, you can pass `metadata_only=true` to the function: + +```jinja2 +{% set section = get_section(path="blog/_index.md", metadata_only=true) %} +``` + ### ` get_url` Gets the permalink for the given path. If the path starts with `./`, it will be understood as an internal @@ -108,11 +114,11 @@ we want to link to the file that is located at `static/css/app.css`: {{/* get_url(path="css/app.css") */}} ``` -For assets it is reccommended that you pass `trailing_slash=false` to the `get_url` function. This prevents errors -when dealing with certain hosting providers. An example is: +By default, assets will not have a trailing slash. You can force one by passing `trailing_slash=true` to the `get_url` function. +An example is: ```jinja2 -{{/* get_url(path="css/app.css", trailing_slash=false) */}} +{{/* get_url(path="css/app.css", trailing_slash=true) */}} ``` In the case of non-internal links, you can also add a cachebust of the format `?t=1290192` at the end of a URL