Expand description
The export export: renders one of the manifest’s [[exporters]] formats from the story, and
returns the file’s bytes.
An exporter whose manifest entry sets images = true gets the files of the images the story shows
in Request::images, and with cover = true as well, the project’s cover. In markdown, an image
is , which crate::images reads; in prose, a line holding only an
image is a block {"type": "image", "id": 5, "name": "Map"}, which prose_image_id reads. An image
inside a line, or one whose file Hammer could not read, is its name as text, never a block.
let request: hammer::export::Request = hammer::input_json()?;
for scene in request.chapters.iter().flat_map(|chapter| &chapter.scenes) {
for id in hammer::images::find_ids(scene) {
if let Some(image) = request.image(id) { /* image.content holds the file */ }
}
}An exporter whose manifest entry sets output = "archive" returns an Archive instead: files that
Hammer zips, in order, into the one export file, whose extension and mime the manifest still
gives (zip and application/zip). An image Hammer sent is named by its id, and Hammer writes its
bytes, so the reply carries none.
let mut archive = hammer::export::Archive::new();
archive.text("story.md", story)?;
for image in &request.images {
archive.image(&format!("images/{}.{}", image.id, image.extension), image)?;
}
archive.to_json()Structs§
- Archive
- What the
exportexport returns, as Archive::to_json, for a format whose manifest entry setsoutput = "archive": files Hammer zips in the order they were added. - Chapter
- A chapter’s scenes: as markdown in
scenes, or, for a format whose manifest entry setsinput = "prose", inproseas Hammer’s parsed blocks, one list of blocks per scene. - Image
- A project image and its file:
image.get’s crate::ops::ImageContent withmime_typeadded. - Request
Traits§
- Archive
Image - What Archive::image names an image of Request::images by: its id, or the Image itself.
Functions§
- prose_
image_ id - The id of a prose
imageblock,{"type": "image", "id": 5, "name": "Map"}; none for any other block.