Skip to content

Commit

Permalink
Automatic generation of indexes for exercises folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Nov 5, 2024
1 parent 447b194 commit 1cf4da8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 11 additions & 4 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ FIL_TEMPLATES = $(TEMPLATES)filters/
# Files
# -------------------------------


## Pre-req files
## (md files generated by other rules)

# UML class diagrams (source and target).
SOURCE_CLA_TXT_FILES := $(shell find $(CLA_DIR) -mindepth 1 -maxdepth 1 -iname "*.txt")
TARGET_CLA_MD_FILES := $(addsuffix .md, $(basename $(SOURCE_CLA_TXT_FILES)))
Expand All @@ -116,14 +120,14 @@ TARGET_CLA_TXT_FILES := $(addprefix $(BUILD_DIR), $(SOURCE_CLA_TXT_FILES))
# Exercises files (with and without solution)
SOURCE_EXO_W_SOL := $(shell find $(EXO_W_SOL_DIR) -name '*.md')
TARGET_EXO_WO_SOL := $(subst exercises_w_sol,exercises,$(SOURCE_EXO_W_SOL))
TARGET_EXO_WO_SOL_WITHOUT_INDEX := $(filter-out index.md %/index.md,$(TARGET_EXO_WO_SOL))

## md files

# We have two sources, one containing the index.md files,
# (including at root level), and one that doesn't.
SOURCE_MD_FILES := $(shell find $(MD_DIRS) -name '*.md')
SOURCE_MD_FILES += index.md
SOURCE_MD_FILES += $(TARGET_EXO_WO_SOL_WITHOUT_INDEX)
SOURCE_MD_FILES += $(TARGET_EXO_WO_SOL)
# md files without the index.md files in a folder.
# Those files only contain the title of the folder.
# cf. https://quartz.jzhao.xyz/authoring-content
Expand All @@ -147,6 +151,8 @@ TARGET_DOC_FILES_WITHOUT_INDEX := $(addsuffix .docx, $(basename $(TARGET_MD_FILE
# Note that we use the order file, discussed below (look for "order").
SOURCE_BOOK := $(shell cat order | grep -E "./lectures/.*.md|./docs/.*md")

## Other files

# Font files (source and target).
SOURCE_WOFF_FONT_FILES := $(shell find $(FONT_DIR) -iname "*.woff*")
TARGET_WOFF_FONT_FILES := $(addprefix $(BUILD_DIR), $(SOURCE_WOFF_FONT_FILES))
Expand All @@ -165,7 +171,6 @@ TARGET_PROJECTS_FILES := $(addprefix $(BUILD_DIR), $(addsuffix .zip, $(PROJECTS_
# File where to get the metadata
METADATA_FILE = $(TEMPLATES)meta.yaml


# ===============================
# Options and variables
# ===============================
Expand Down Expand Up @@ -308,13 +313,15 @@ $(CLA_DIR)%.md: $(CLA_DIR)%.txt

# Exercise without solution
.PHONY: EXE
EXE: $(TARGET_EXO_WO_SOL_WITHOUT_INDEX)
EXE: $(TARGET_EXO_WO_SOL)

$(EXO_DIR)%.md: $(EXO_W_SOL_DIR)%.md
@echo "Creating $@"
@mkdir -p $(dir $@) \
&& cp $< $@ \
&& sed -i '/<details>/,/<\/details>/d' $@ \
&& sed -i 's/title: Exercises with solutions/title: Exercises/g' $@ \
&& sed -i 's-Exercises \*without\* solutions \[are also available\](\./exercises/)\.-Exercises *with* solutions [are also available](./exercises_w_sol/).-g' $@ \
&& sed -i 's/\[x\]/[ ]/g' $@ \
&& sed -i 's/ (with solutions)//g' $@ \
&& sed -i '1 i\<!--\n\nDO NOT EDIT THIS FILE\n\nEdit $<, and run\nmake $@\ninstead.\n-->\n' $@ \
Expand Down
7 changes: 0 additions & 7 deletions source/exercises/index.md

This file was deleted.

0 comments on commit 1cf4da8

Please sign in to comment.