From c015b713bea6b3ec12c4fbe7fb362bf6e9620e0e Mon Sep 17 00:00:00 2001 From: Keyhan Vakil Date: Sun, 4 Jun 2017 23:33:53 -0700 Subject: [PATCH] added include_recent --- log.tex | 2 +- lua/includer.moon | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/log.tex b/log.tex index 2e23071..309da76 100644 --- a/log.tex +++ b/log.tex @@ -11,7 +11,7 @@ \begin{luacode} local includer = require "lua.includer" -includer.include_year("2017") +includer.include_recent("2017", 10) \end{luacode} \end{document} diff --git a/lua/includer.moon b/lua/includer.moon index 2237cb7..dd146a8 100644 --- a/lua/includer.moon +++ b/lua/includer.moon @@ -107,12 +107,24 @@ output_month_entry = (filename) -> tex.sprint "\\chapter{#{nice_month filename}}" tex.sprint "\\clearpage" +--- includes recent entries +-- @tparam string year the year as a string (e.g. "2017") +-- @tparam int n the number of entries to include +lua.includer.include_recent = (year, n) -> + all_files = include year + entry_files = [f for f in skeys all_files when is_day_entry(f) or is_month(f)] + -- @todo always include month including the days + skip = #entry_files - n + for _, filename in pairs entry_files + if skip < 1 + if is_day_entry filename + output_day_entry filename + elseif is_month filename + output_month_entry filename + else + skip -= 1 + --- includes all files in the directory year/ -- @tparam string year the year as a string (e.g. "2017") lua.includer.include_year = (year) -> - all_files = include year - for filename in skeys all_files - if is_day_entry filename - output_day_entry filename - elseif is_month filename - output_month_entry filename + lua.includer.include_recent year, math.huge