Function hugo_to_json::convert_to_json_and_write[][src]

pub fn convert_to_json_and_write(
    contents_directory: PathBuf,
    output_location: Option<PathBuf>,
    drafts: bool
) -> Result<(), HugotoJsonError>

Converts a Hugo contents directory to JSON and writes it to a given location. If the output location is provided and it doesn’t exist, it will be created. If no output location it will write to stdout.

Examples

A basic example that writes to stdout.

use hugo_to_json::convert_to_json_and_write;
use std::path::PathBuf;
convert_to_json_and_write(PathBuf::from("/home/example_user/documents/blog/contents/"), None, false)?;

An example that writes to a file.

use hugo_to_json::convert_to_json_and_write;
use std::path::PathBuf;

let result = convert_to_json_and_write(PathBuf::from("/home/example_user/documents/blog/contents/"), Some(PathBuf::from("/home/example_user/documents/blog/static/index.json")), false)?;

Errors

Errors can occur if there is an error accessing the contents directory, serializing the page index to JSON, or performing IO writing the result out to either stdout or a file.