# Books and Websites {#chp:sites}

Books and websites are usually based on multiple input files under a directory.
For a directory to be recognized as a book or website project, it needs to
contain a configuration file named `_litedown.yml`.

If you want to customize the output formats `html_format` or `latex_format` for
books or websites, you should do it in `_litedown.yml`, e.g.,

``` yaml
output:
  litedown::html_format:
    options:
      toc:
        depth: 4
  litedown::latex_format:
    meta:
      documentclass: "book"
```

## Books

The `_litedown.yml` file should contain a top-level field named `book`, which
currently supports these options:

``` yaml
book:
  new_session: false
  subdir: false
  pattern: "[.]R?md$"
  chapter_before: "Information before a chapter."
  chapter_after: "This chapter was generated from `$input$`."
```

You can choose whether to render each input file in a new R session, whether to
search subdirectories for input files, the types of input files (e.g., you can
use `.md` or `.R` files if you want), and additional information to be included
before/after each chapter, in which you can use some variables such as
`$input$`, which is the path of each input file.

### R package documentation

R package developers can build the full package documentation as a book. A
series of helper functions have been provided in **litedown** to get various
information about the package, such as the package description (`pkg_desc()`),
news (`pkg_news()`), citation (`pkg_citation()`), source code (`pkg_code()`),
and all manual pages (`pkg_manual()`). You can call these functions in code
chunks to print out the desired information. For example, you may put them in
the appendix (@sec:appendices):

```` md
# Appendix {.appendix}

# Package Metadata

```{r, echo=FALSE}
litedown::pkg_desc()
```

To cite the package:

```{r, echo=FALSE}
litedown::pkg_citation()
```

# News

```{r, echo=FALSE}
litedown::pkg_news(recent = 0)  # show full news
```

# Manual pages

```{r, echo=FALSE}
litedown::pkg_manual()
```

# Source code

```{r, echo=FALSE}
litedown::pkg_code()
```
````

## Websites

The `_litedown.yml` file should contain a top-level field named `site`, and you
are likely to customize the `meta` variables `css`, `include_before`, and
`include_after` for the `html_format`, e.g.,

``` yaml
site:
  rebuild: "outdated"
  pattern: "[.]R?md$"

output:
  litedown::html_format:
    meta:
      css: ["@default"]
      include_before: "[Home](/) [About](/about.html)"
      include_after: "&copy; 2024 | [Edit]($input$)"
```

Basically, `include_before` can take a file or text input that will be used as
the header of each web page, and `include_after` will be the footer.
