Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create single page html for use on ebook readers #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ root = true

[*]
charset = utf-8
indent_style = space
#indent_style = space
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#indent_style = space
indent_style = space

Copy link
Author

@kodfodrasz kodfodrasz Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First: this PR is just a PoC/hack. I needed this change because VS Code kept corrupting my makefiles, where the rule blocks are mandatorily starting with a single tab indent. I spent a few minutes trying to work this out, then simply issued this, as my goal was not fixing the VS Code editorconfig/makefile support, but generating beancount docs.

The problem root cause might be fixed upstream already.

insert_final_newline = true

[*.py]
indent_size = 4

[*.yml]
indent_size = 2

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions ebook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
preprocessed/
beancount.html
84 changes: 84 additions & 0 deletions ebook/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
CHAPTERS= \
index.md \
command_line_accounting_in_context.md \
the_double_entry_counting_method.md \
installing_beancount.md \
running_beancount_and_generating_reports.md \
getting_started_with_beancount.md \
beancount_language_syntax.md \
beancount_options_reference.md \
precision_tolerances.md \
beancount_query_language.md \
beancount_cheat_sheet.md \
how_inventories_work.md \
exporting_your_portfolio.md \
tutorial_example.md \
beancount_history_and_credits.md \
a_comparison_of_beancount_and_ledger_hledger.md \
fetching_prices_in_beancount.md \
importing_external_data.md \
command_line_accounting_cookbook.md \
trading_with_beancount.md \
stock_vesting_in_beancount.md \
sharing_expenses_with_beancount.md \
how_we_share_expenses.md \
health_care_expenses.md \
calculating_portolio_returns.md \
beancount_scripting_plugins.md \
beancount_design_doc.md \
ledgerhub_design_doc.md \
external_contributions.md \
a_proposal_for_an_improvement_on_inventory_booking.md \
settlement_dates_in_beancount.md \
balance_assertions_in_beancount.md \
fund_accounting_with_beancount.md \
rounding_precision_in_beancount.md \
beancount_v3.md \
installing_beancount_v3.md \
beancount_v3_dependencies.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to read the chapter list from index.json?

Maybe this makefile can be replaced with a shorter python script

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

Also I agree about the short py script, I just needed to get stuff done. I will have some time a few weeks later, I'll try to get back to this, but also fell free to improve/reimplement it, if you have capacity.

Thanks for the valuable feedback, and ideas!


# CHAPTERS= \
# index.md \
# command_line_accounting_in_context.md \
# beancount_v3_dependencies.md

DOCS_DIR=../docs
PREPROCESSED_DIR=preprocessed

SOURCES=$(foreach c,$(CHAPTERS),$(DOCS_DIR)/$c)
PREPROCESSED=$(foreach c,$(CHAPTERS),preprocessed/$c)

all: clean preprocess ebook

clean:
rm -rf "$(PREPROCESSED_DIR)" beancount.html

$(PREPROCESSED_DIR):
mkdir -p "$@"

$(PREPROCESSED_DIR)/%.md: $(DOCS_DIR)/%.md $(PREPROCESSED_DIR)
cp "$<" "$@"
# cp -R $(basename $<) $(PREPROCESSED_DIR)/ || true
sed -i -e 's@<a id="\(.*\)"></a>@<a id="$(notdir $<).\1"></a>@' $@
sed -i -e 's@](#\(.*\))@](#$(notdir $<).\1)@' $@
sed -i -e 's@](\(.*\.md\))@](#\1\.title)@' $@

preprocess: $(PREPROCESSED)
@echo "Preprocess done!"

ebook: beancount.html
@echo "Ebook done!"

beancount.html: preprocess
pandoc \
--from markdown \
--to html \
--resource-path $(DOCS_DIR) \
--standalone \
--self-contained \
--metadata-file=metadata.yaml \
--output $@ \
$(PREPROCESSED)

.PHONY: all preprocess clean ebook
.DELETE_ON_ERROR:
13 changes: 13 additions & 0 deletions ebook/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "Beancount User's Manual"
# subtitle: "This is the subtitle"
author:
- Martin Blais
# - Author Two
# description: |
# This is a long
# description.

# It consists of two paragraphs
# ...
---