Skip to content

Commit

Permalink
Completely rework the file structure and the project ideology 🛸
Browse files Browse the repository at this point in the history
  • Loading branch information
nishogi committed Jul 19, 2024
1 parent f40e9c3 commit 556f7bd
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 136 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/pandoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ name: Build and Push PDF Document
on:
push:
paths:
- '.github/workflows/*'
- 'md/*'
- ".github/workflows/*"
- "docs/md/*"

jobs:
build:
runs-on: ubuntu-latest
container:

container:
image: knsit/pandoc:latest
options: --user root

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build PDF
run: |
cd "$SOURCE_DIR"
pandoc -s -o "$DEST_FILE_NAME" -f "$SOURCE_FORMAT" --data-dir="$DATA_DIR" --template "$TEMPLATE" --toc --listings --columns=50 --number-sections --dpi=300 --pdf-engine xelatex -M date="$(date +%Y-%m-%d)" md/HEADER.YAML md/*.md
pandoc -s -o "$DEST_FILE_NAME" -f "$SOURCE_FORMAT" --data-dir="$DATA_DIR" --template "$TEMPLATE" --toc --listings --columns=50 --number-sections --dpi=300 --pdf-engine xelatex -M date="$(date +%Y-%m-%d)" docs/md/HEADER.YAML docs/md/*.md
env:
DEST_FILE_NAME: "artifact.pdf"
DEST_FILE_NAME: "docs/artifact.pdf"
TEMPLATE: "eisvogel.tex"
SOURCE_FORMAT: markdown_strict+backtick_code_blocks+pipe_tables+auto_identifiers+yaml_metadata_block+implicit_figures+table_captions+footnotes+smart+escaped_line_breaks+header_attributes
DATA_DIR: pandoc
DATA_DIR: docs/pandoc

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifact
path: artifact.pdf
path: docs/artifact.pdf

push_pdf:
needs: build
Expand All @@ -47,12 +47,12 @@ jobs:
uses: actions/download-artifact@v4
with:
name: artifact
path: .
path: docs/.

- name: Commit PDF
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add artifact.pdf
git add docs/artifact.pdf
git commit -m "Add or update PDF" || echo "No changes to commit"
git push
git push
40 changes: 7 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
# pdf-from-markdown

This repository is an exploration of how to generate a PDF from a Markdown file using Pandoc.
A fast and efficient way to generate PDF files from Markdown files. Perfect for markdown enjoyers that need to communicate with pdf lovers.

## Requirements
## Get Started

- [Pandoc](https://pandoc.org/)
- [LaTeX](https://www.latex-project.org/get/)
- Latex packages : <br>
```sudo tlmgr install adjustbox footnotebackref pagecolor csquotes mdframed zref needspace sourcesanspro sourcecodepro titling selnolig lualatex-math``` (for Mac users)

## Usage

There are three levels of complexity:

### 1. A simple PDF file with no special formatting.

To generate the PDF, run the following command:

```bash
pandoc README.md -o README.pdf
```

[And here is the result !](README.pdf)

### 2. Usage of a template to generate a PDF with a title page and better looking.

We are using the template eisvogel.tex from the [pandoc-latex-template](https://github.com/Wandmalfarbe/pandoc-latex-template) repository.

To generate the PDF, run the following command:
To set up the generation of the PDF files, navigate to your project folder and run the following command:

```bash
pandoc -s -o document.pdf -f markdown_strict+backtick_code_blocks+pipe_tables+auto_identifiers+yaml_metadata_block+implicit_figures+table_captions+footnotes+smart+escaped_line_breaks+header_attributes --data-dir=pandoc --template eisvogel.tex --toc --listings --columns=50 --number-sections --dpi=300 --pdf-engine xelatex -M date="$(date +%Y-%m-%d)" md/HEADER.YAML md/*.md
git archive --remote=https://github.com/Nishogi/pdf-from-markdown.git | tar -x
```
[And here is the result !](document.pdf)

### 3. Automate the generation of the PDF using GitHub Actions.

See the [GitHub Actions workflow file](.github/workflows/pandoc.yml) for more details.
Now, upon push, the Markdown files in the `docs/md` directory are compiled into a single PDF file and pushed to the `docs` directory.

And the artifacts generated by the workflow are available in the [Actions tab](https://github.com/Nishogi/pdf-from-markdown/actions/) of this repository.
## Contributing

It is also pushed [at the root of the repository.](artifact.pdf)
Feel free to use and/or contribute to the project!
Binary file removed README.pdf
Binary file not shown.
Binary file removed artifact.pdf
Binary file not shown.
File renamed without changes
File renamed without changes
30 changes: 30 additions & 0 deletions docs/md/00-Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Introduction

This document explores how to generate a PDF from a Markdown file using Pandoc.

## Requirements

Here are the requirements for each level of complexity described in the next section:

### Level 1

- [Pandoc](https://pandoc.org/)
- [LaTeX](https://www.latex-project.org/get/)

### Level 2

- Pandoc
- LaTeX
- LaTeX packages:
```bash
sudo tlmgr install adjustbox footnotebackref pagecolor csquotes mdframed zref needspace sourcesanspro sourcecodepro titling selnolig lualatex-math
```
(for Mac users)

### Level 3

None! Everything is done in a container in the cloud.

## Contributors

This is a small project I did in my free time to help generate good-looking documentation for my school projects. Feel free to make pull requests!
41 changes: 41 additions & 0 deletions docs/md/01-Usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Usage

There are three levels of complexity:

## Simple PDF Generation

To generate a basic PDF without special formatting, use:

```bash
pandoc <file.md> -o <file.pdf>
```

## Enhanced PDF with Template

To generate a PDF that uses the `eisvogel.tex` template from the [pandoc-latex-template](https://github.com/Wandmalfarbe/pandoc-latex-template) repository, use:

```bash
pandoc -s -o <file.pdf> -f markdown_strict+backtick_code_blocks+pipe_tables+auto_identifiers+yaml_metadata_block+implicit_figures+table_captions+footnotes+smart+escaped_line_breaks+header_attributes --data-dir=pandoc --template eisvogel.tex --toc --listings --columns=50 --number-sections --dpi=300 --pdf-engine=xelatex -M date="$(date +%Y-%m-%d)" md/HEADER.YAML md/*.md
```

Ensure your directory structure is as follows:

```plaintext
.
+-- assets
| +-- (...)
| +-- your-assets.png
+-- md
| +-- (...)
| +-- your-files.md
| +-- HEADER.YAML
+-- pandoc
+-- templates
+-- eisvogel.tex
```

## Automated PDF Generation with GitHub Actions

Artifacts generated by the workflow are available in the [Actions tab](https://github.com/Nishogi/pdf-from-markdown/actions) of this repository and are also pushed to the root of the `docs` folder.

For more details, check the GitHub workflow file.
19 changes: 19 additions & 0 deletions docs/md/99-Sources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Sources

Markdown Syntax

> https://www.markdownguide.org/basic-syntax/
![Markdown Cheatsheet](docs/assets/cheatsheet.png)

CI with Pandoc

> https://gitlab.com/pandoc/pandoc-ci-example
Templating with Pandoc

> https://github.com/alexeygumirov/pandoc-for-pdf-how-to
GitHub Actions

> https://docs.github.com/en/actions
3 changes: 2 additions & 1 deletion md/HEADER.YAML → docs/md/HEADER.YAML
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ titlepage-color: "FFFFFF"
titlepage-text-color: "000000"
titlepage-rule-color: "CCCCCC"
titlepage-rule-height: 4
titlepage-logo: "assets/pandoc.png"
titlepage-logo: "docs/assets/pandoc.png"
logo-width: 100pt
page-background:
page-background-opacity:
Expand All @@ -29,3 +29,4 @@ subparagraph: true
lang: en-US
toc-own-page: true
---

File renamed without changes.
Binary file removed document.pdf
Binary file not shown.
15 changes: 0 additions & 15 deletions md/00-Introduction.md

This file was deleted.

62 changes: 0 additions & 62 deletions md/01-Usage.md

This file was deleted.

13 changes: 0 additions & 13 deletions md/99-Sources.md

This file was deleted.

0 comments on commit 556f7bd

Please sign in to comment.