Skip to content

Commit

Permalink
add Makefile to create docx documents from the wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
scholarsmate committed Sep 28, 2023
1 parent c860008 commit fe1036b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Requires: make, git, sed, and pandoc

# Directory containing the wiki markdown files
SRCDIR := .wiki/

# Filter out .md files starting with underscore and generate corresponding .docx filenames
DOCX = $(addsuffix .docx, $(filter-out _%, $(basename $(notdir $(wildcard $(SRCDIR)*.md)))))

# Function to sanitize filenames
sanitize = $(shell echo $(1) | sed -e 's/[^a-zA-Z0-9.\-]/_/g' -e 's/__*/_/g' -e 's/_\-/-/g')

# Target to clone the git wiki repository
$(SRCDIR):
git clone https://github.com/apache/daffodil-vscode.wiki.git $(SRCDIR)

# Target to generate docx from md
%.docx:
@# Convert img tags to markdown syntax for pandoc
sed -r 's!<img[^>]* src="([^"]+)"[^>]*>!\![](\1)!g' "$(SRCDIR)$(addsuffix .md,$(basename $@))" | pandoc -t docx -f gfm --resource-path=$(SRCDIR) --toc=true -o "$(call sanitize,$@)" -

# Target to update the wiki repository
update: $(SRCDIR)
git -C $(SRCDIR) pull

# Main target to update the repo and then generate the docx files
all: update
${MAKE} $(DOCX)

# Cleanup target
clean:
rm -rf *.docx $(SRCDIR)

.PHONY: update all clean

0 comments on commit fe1036b

Please sign in to comment.