Skip to content

[Discussion] Book representation #146

Closed
@azerupi

Description

@azerupi

Currently, the internal representation is very uni-language focused. We have one struct MDBook containing all the information and the chapters for the book.

To support multiple languages we have to store multiple books with different metadata. There should be one default language, the rest are assumed to be translations.

I propose that MDBook holds a hashmap with language codes like "en" or "fr" as keys and Books as values.

pub struct MDBook<'a> {
    books: HashMap<&'a str, Book>,
    // Other fields omitted 
}         

The Book structure would be defined as follows:

pub struct Book {
    metadata: BookMetadata,

    preface: Vec<Chapter>,
    chapters: Vec<Chapter>,
    appendix: Vec<Chapter>,
}

Chapter would be

pub struct Chapter {
    title: String,
    file: path::PathBuf,

    sub_chapters: Vec<Chapter>,
}

And BookMetadata would be

pub struct BookMetadata {
    pub title: String,
    pub description: String,

    pub language: Language,

    authors: Vec<Author>,
    translators: Vec<Author>,
}

And finally Author and Language would be

pub struct Author {
    name: String,
    email: Option<String>,
}

pub struct Language {
    name: String,
    code: String,
}

This is what PR #147 implements. (not merged)

It allows to represent multiple languages, each with different book structures, authors / translators etc.

Open questions

  • Would there be a better way to represent the books?
  • How do we represent the default language?
    Store the key (language code) for the default language in MDBook?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions