Compare commits
No commits in common. "ea8c4cc8c43e415c8a983d3dbf12229b6376db39" and "4cbbd2961e84104724d29fb35c0b514d1101ce2b" have entirely different histories.
ea8c4cc8c4
...
4cbbd2961e
67
Makefile
67
Makefile
@ -18,17 +18,16 @@
|
|||||||
# change these to fir your project
|
# change these to fir your project
|
||||||
#
|
#
|
||||||
|
|
||||||
# root dir for the project, all other paths relative to PROJECT_DIR (except for OUT_DIR and DEP_DIR)
|
# root dir for the project, all other paths relative to PROJECT_DIR (except for OUT_DIR)
|
||||||
PROJECT_DIR = src
|
PROJECT_DIR = .
|
||||||
|
|
||||||
# path where final website will be in, this one is not relative to PROJECT_DIR
|
# path where final website will be in, this one is not relative to PROJECT_DIR
|
||||||
OUT_DIR = build
|
OUT_DIR = ../quintern-test
|
||||||
|
|
||||||
# SOURCE FILES:
|
# SOURCE FILES:
|
||||||
# all SRC_FLS and all files (recursively) in the SRC_DIRS will be built
|
# all SRC_FLS and all files in the SRC_DIRS will be built
|
||||||
# all files in PROJECT_DIR (not recursively) are source files
|
|
||||||
SRC_DIRS = de en script style
|
SRC_DIRS = de en script style
|
||||||
SRC_FLS =
|
SRC_FLS = rss.xml
|
||||||
|
|
||||||
# SOURCE FILES:
|
# SOURCE FILES:
|
||||||
# all RESOURCE_FLS and all files in the RESOURCE_DIRS will be copied to OUT_DIR
|
# all RESOURCE_FLS and all files in the RESOURCE_DIRS will be copied to OUT_DIR
|
||||||
@ -42,8 +41,7 @@ RESOURCE_FLS =
|
|||||||
# foreach lang in LANGS:
|
# foreach lang in LANGS:
|
||||||
# run HTML_PP_CMD with --var lang=lang on file and output to OUT_DIR without the COMMON_DIR prefix, so COMMON_DIR/subdir/file.html -> OUT_DIR/lang/subdir/file.html
|
# run HTML_PP_CMD with --var lang=lang on file and output to OUT_DIR without the COMMON_DIR prefix, so COMMON_DIR/subdir/file.html -> OUT_DIR/lang/subdir/file.html
|
||||||
# all non-html files will handled the same way, but without the preprocessor being run on them. They are simply copied
|
# all non-html files will handled the same way, but without the preprocessor being run on them. They are simply copied
|
||||||
# leave COMMON_DIR empty to disable multi-lang feature
|
COMMON_DIR = common
|
||||||
COMMON_DIR =
|
|
||||||
LANGS = de en
|
LANGS = de en
|
||||||
|
|
||||||
# PREPROCESSOR
|
# PREPROCESSOR
|
||||||
@ -53,7 +51,7 @@ INCLUDE_DIR = include
|
|||||||
|
|
||||||
# ADVANCED
|
# ADVANCED
|
||||||
# the command to run the html preprocessor
|
# the command to run the html preprocessor
|
||||||
HTML_PP_CMD = python3 html-preprocessor --exit-on light
|
HTML_PP_CMD = python3 html_preprocessor.py --exit-on light
|
||||||
|
|
||||||
DEP_DIR = .dependencies
|
DEP_DIR = .dependencies
|
||||||
|
|
||||||
@ -72,14 +70,12 @@ _RES_DIRS = $(addprefix $(PROJECT_DIR)/, $(RESOURCE_DIRS))
|
|||||||
_RES_FLS = $(addprefix $(PROJECT_DIR)/, $(RESOURCE_FLS))
|
_RES_FLS = $(addprefix $(PROJECT_DIR)/, $(RESOURCE_FLS))
|
||||||
_COMMON_DIR = $(addprefix $(PROJECT_DIR)/, $(COMMON_DIR))
|
_COMMON_DIR = $(addprefix $(PROJECT_DIR)/, $(COMMON_DIR))
|
||||||
_INCLUDE_DIR = $(addprefix $(PROJECT_DIR)/, $(INCLUDE_DIR))
|
_INCLUDE_DIR = $(addprefix $(PROJECT_DIR)/, $(INCLUDE_DIR))
|
||||||
|
_DEP_DIR = $(addprefix $(PROJECT_DIR)/, $(DEP_DIR))
|
||||||
|
|
||||||
# NORMAL SRC
|
# NORMAL SRC
|
||||||
# all SRC_DIRS + all subdirs of each srcdir
|
# all SRC_DIRS + all subdirs of each srcdir
|
||||||
_SRC_SUB_DIRS = $(foreach srcdir, $(_SRC_DIRS), $(shell find $(srcdir)/ -type d 2>/dev/null))
|
_SRC_SUB_DIRS = $(foreach srcdir, $(_SRC_DIRS), $(shell find $(srcdir)/ -type d))
|
||||||
# add files in project dir
|
_SRC_FLS += $(foreach srcdir, $(_SRC_DIRS), $(shell find $(srcdir)/ -type f))
|
||||||
_SRC_FLS += $(shell find $(PROJECT_DIR)/ -maxdepth 1 -type f)
|
|
||||||
# add files src dirs, recursively
|
|
||||||
_SRC_FLS += $(foreach srcdir, $(_SRC_DIRS), $(shell find $(srcdir)/ -type f 2>/dev/null))
|
|
||||||
# OUT_DIRS = $(OUT_DIR) $(addprefix $(OUT_DIR)/, $(_SRC_SUB_DIRS))
|
# OUT_DIRS = $(OUT_DIR) $(addprefix $(OUT_DIR)/, $(_SRC_SUB_DIRS))
|
||||||
OUT_DIRS = $(OUT_DIR)/ $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_SRC_SUB_DIRS))
|
OUT_DIRS = $(OUT_DIR)/ $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_SRC_SUB_DIRS))
|
||||||
# path of the source files after being processed
|
# path of the source files after being processed
|
||||||
@ -87,13 +83,12 @@ OUT_DIRS = $(OUT_DIR)/ $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_SRC_SUB_D
|
|||||||
OUT_FLS = $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_SRC_FLS))
|
OUT_FLS = $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_SRC_FLS))
|
||||||
|
|
||||||
# RESOURCES
|
# RESOURCES
|
||||||
_RES_SUB_DIRS = $(foreach srcdir, $(_RES_DIRS), $(shell find $(srcdir)/ -type d 2>/dev/null))
|
_RES_SUB_DIRS = $(foreach srcdir, $(_RES_DIRS), $(shell find $(srcdir)/ -type d))
|
||||||
_RES_FLS += $(foreach srcdir, $(_RES_DIRS), $(shell find $(srcdir)/ -type f 2>/dev/null))
|
_RES_FLS += $(foreach srcdir, $(_RES_DIRS), $(shell find $(srcdir)/ -type f))
|
||||||
RES_OUT_DIRS = $(OUT_DIR)/ $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_RES_SUB_DIRS))
|
RES_OUT_DIRS = $(OUT_DIR)/ $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_RES_SUB_DIRS))
|
||||||
RES_OUT_FLS = $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_RES_FLS))
|
RES_OUT_FLS = $(patsubst $(PROJECT_DIR)/%, $(OUT_DIR)/%, $(_RES_FLS))
|
||||||
|
|
||||||
# MULTILANG
|
# MULTILANG
|
||||||
ifdef COMMON_DIR
|
|
||||||
_ML_SRC_FLS = $(shell find $(_COMMON_DIR)/ -type f)
|
_ML_SRC_FLS = $(shell find $(_COMMON_DIR)/ -type f)
|
||||||
_ML_SRC_SUB_DIRS= $(shell find $(_COMMON_DIR)/ -type d)
|
_ML_SRC_SUB_DIRS= $(shell find $(_COMMON_DIR)/ -type d)
|
||||||
# will contain one subdir for each lang, each of which contains every file from ML_SRC_FLS
|
# will contain one subdir for each lang, each of which contains every file from ML_SRC_FLS
|
||||||
@ -101,12 +96,11 @@ ML_OUT_DIR = $(OUT_DIR)
|
|||||||
ML_OUT_LANG_DIRS= $(foreach lang, $(LANGS), $(addprefix $(ML_OUT_DIR)/, $(lang)))
|
ML_OUT_LANG_DIRS= $(foreach lang, $(LANGS), $(addprefix $(ML_OUT_DIR)/, $(lang)))
|
||||||
ML_OUT_DIRS = $(foreach lang, $(LANGS), $(patsubst $(_COMMON_DIR)/%, $(ML_OUT_DIR)/$(lang)/%, $(_ML_SRC_SUB_DIRS)))
|
ML_OUT_DIRS = $(foreach lang, $(LANGS), $(patsubst $(_COMMON_DIR)/%, $(ML_OUT_DIR)/$(lang)/%, $(_ML_SRC_SUB_DIRS)))
|
||||||
ML_OUT_FLS = $(foreach lang, $(LANGS), $(patsubst $(_COMMON_DIR)/%, $(ML_OUT_DIR)/$(lang)/%, $(_ML_SRC_FLS)))
|
ML_OUT_FLS = $(foreach lang, $(LANGS), $(patsubst $(_COMMON_DIR)/%, $(ML_OUT_DIR)/$(lang)/%, $(_ML_SRC_FLS)))
|
||||||
endif
|
|
||||||
|
|
||||||
# needed for creating them
|
# needed for creating them
|
||||||
_DEP_DIRS = $(sort $(patsubst $(OUT_DIR)/%, $(DEP_DIR)/%, $(OUT_DIRS) $(ML_OUT_DIRS)))
|
_DEP_DIRS = $(sort $(patsubst $(OUT_DIR)/%, $(_DEP_DIR)/%, $(OUT_DIRS) $(ML_OUT_DIRS)))
|
||||||
# needed for reading
|
# needed for reading
|
||||||
_DEP_FLS = $(shell find $(DEP_DIR) -type f -name '*.d' 2>/dev/null)
|
_DEP_FLS = $(shell find $(_DEP_DIR) -type f -name '*.d')
|
||||||
|
|
||||||
# PRINTING
|
# PRINTING
|
||||||
FMT_VAR_SRC ="Variable '\e[1;34m%s\e[0m': \e[0;33m%s\e[0m\n"
|
FMT_VAR_SRC ="Variable '\e[1;34m%s\e[0m': \e[0;33m%s\e[0m\n"
|
||||||
@ -140,48 +134,43 @@ print:
|
|||||||
@printf $(FMT_VAR_OUT) "OUT_FLS" "$(OUT_FLS)"
|
@printf $(FMT_VAR_OUT) "OUT_FLS" "$(OUT_FLS)"
|
||||||
@printf $(FMT_VAR_SRC) "_RES_FLS" "$(_RES_FLS)"
|
@printf $(FMT_VAR_SRC) "_RES_FLS" "$(_RES_FLS)"
|
||||||
@printf $(FMT_VAR_OUT) "RES_OUT_FLS" "$(RES_OUT_FLS)"
|
@printf $(FMT_VAR_OUT) "RES_OUT_FLS" "$(RES_OUT_FLS)"
|
||||||
ifdef COMMON_DIR
|
|
||||||
@printf $(FMT_VAR_SRC) "_ML_SRC_FLS" "$(_ML_SRC_FLS)"
|
@printf $(FMT_VAR_SRC) "_ML_SRC_FLS" "$(_ML_SRC_FLS)"
|
||||||
@printf $(FMT_VAR_OUT) "ML_OUT_FLS" "$(ML_OUT_FLS)"
|
@printf $(FMT_VAR_OUT) "ML_OUT_FLS" "$(ML_OUT_FLS)"
|
||||||
endif
|
|
||||||
@printf $(FMT_VAR_SRC) "_DEP_FLS" "$(_DEP_FLS)"
|
@printf $(FMT_VAR_SRC) "_DEP_FLS" "$(_DEP_FLS)"
|
||||||
@# @printf $(FMT_VAR_SRC) "y" "$(y)"
|
@# @printf $(FMT_VAR_SRC) "y" "$(y)"
|
||||||
|
|
||||||
# DIRECTORIES
|
# MULTILANG RULES
|
||||||
$(sort $(ML_OUT_DIRS) $(_DEP_DIRS) $(RES_OUT_DIRS) $(OUT_DIRS)):
|
$(sort $(ML_OUT_DIRS) $(_DEP_DIRS) $(RES_OUT_DIRS) $(OUT_DIRS)):
|
||||||
@printf $(FMT_DIR) "$@"
|
@printf $(FMT_DIR) "$@"
|
||||||
@mkdir -p $@
|
@mkdir -p $@
|
||||||
|
|
||||||
# MULTILANG RULES
|
# build/ml_tmp/lang/subdir/xyz.html
|
||||||
ifdef COMMON_DIR
|
|
||||||
# $@ is the target to trigger the rule, but all languages have to be built now
|
|
||||||
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%.html): $(_COMMON_DIR)/%.html | $(ML_OUT_DIRS) $(_DEP_DIRS)
|
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%.html): $(_COMMON_DIR)/%.html | $(ML_OUT_DIRS) $(_DEP_DIRS)
|
||||||
@RAW_TARGET=`echo $@ $(foreach lang, $(LANGS), | sed 's|$(ML_OUT_DIR)/$(lang)/||')`;\
|
@#echo "$$@=$@, $$<=$< $$^=$^"
|
||||||
for lang in $(LANGS); do \
|
@# \$@=build/ml_tmp/lang/subdir/xyz.html, \$<=common/subdir/xyz.html
|
||||||
target=$(ML_OUT_DIR)/$$lang/$$RAW_TARGET;\
|
@lang=`echo $(patsubst $(ML_OUT_DIR)/%, %, $@) | awk -F "/" '{print $$1}'`; \
|
||||||
printf $(FMT_OUT_ML_HTML) "$$lang" "$<" "$$target"; \
|
printf $(FMT_OUT_ML_HTML) "$$lang" "$<" "$@"; \
|
||||||
$(HTML_PP_CMD) --input "$<" --output "$$target" --var include_dir=$(_INCLUDE_DIR) --var lang=$$lang --output-deps "`echo $${target}.d | sed 's|$(OUT_DIR)/|$(DEP_DIR)/|'`"; \
|
$(HTML_PP_CMD) --target "$<" --output "$@" --var include_dir=$(_INCLUDE_DIR) --var lang=$$lang --output-deps "$(patsubst $(OUT_DIR)/%, $(_DEP_DIR)/%.d, $@)";
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# rule for all not html files
|
# rule for all not html files
|
||||||
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%): $(_COMMON_DIR)/% | $(ML_OUT_DIRS)
|
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%): $(_COMMON_DIR)/% | $(ML_OUT_DIRS)
|
||||||
@lang=`echo $(patsubst $(ML_OUT_DIR)/%, %, $@) | awk -F "/" '{print $$1}'`; \
|
@lang=`echo $(patsubst $(ML_OUT_DIR)/%, %, $@) | awk -F "/" '{print $$1}'`; \
|
||||||
printf $(FMT_OUT_ML_OTHER) "$$lang" "$<" "$@" ; \
|
printf $(FMT_OUT_ML_OTHER) "$$lang" "$<" "$@" ; \
|
||||||
cp $< $@
|
cp $< $@
|
||||||
endif
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# (NORMAL/RE-)SOURCE RULES
|
# (NORMAL/RE-)SOURCE RULES
|
||||||
#
|
#
|
||||||
$(OUT_DIR)/%.html: $(PROJECT_DIR)/%.html | $(OUT_DIRS) $(_DEP_DIRS)
|
|
||||||
|
|
||||||
|
$(OUT_DIR)/%.html: %.html | $(OUT_DIRS) $(_DEP_DIRS)
|
||||||
@printf $(FMT_OUT_HTML) "$<" "$@";
|
@printf $(FMT_OUT_HTML) "$<" "$@";
|
||||||
@$(HTML_PP_CMD) --input "$<" --output "$@" --var include_dir=$(_INCLUDE_DIR) --output-deps "$(subst $(DEP_DIR)/$(PROJECT_DIR), $(DEP_DIR), $(DEP_DIR)/$<.d)";
|
$(HTML_PP_CMD) --target "$<" --output "$@" --var include_dir=$(_INCLUDE_DIR) --output-deps "$(_DEP_DIR)/$<.d";
|
||||||
@# remove comments and empty lines. two separate lines bc the substitution might create new empty lines
|
@# remove comments and empty lines. two separate lines bc the substitution might create new empty lines
|
||||||
@#awk -i inplace '{FS="" sub(/<!--.*-->/,"")}1' $@
|
@#awk -i inplace '{FS="" sub(/<!--.*-->/,"")}1' $@
|
||||||
@#awk -i inplace '{if (NF != 0) print}' $@
|
@#awk -i inplace '{if (NF != 0) print}' $@
|
||||||
|
|
||||||
$(OUT_DIR)/%: $(PROJECT_DIR)/% | $(OUT_DIRS) $(RES_OUT_DIRS)
|
$(OUT_DIR)/%: % | $(OUT_DIRS) $(RES_OUT_DIRS)
|
||||||
@printf $(FMT_OUT_OTHER) "$<" "$@"
|
@printf $(FMT_OUT_OTHER) "$<" "$@"
|
||||||
@cp -r $< $@
|
@cp -r $< $@
|
||||||
|
|
||||||
@ -196,8 +185,8 @@ stop:
|
|||||||
killall nginx
|
killall nginx
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm $(OUT_FLS) $(ML_OUT_FLS) 2>/dev/null
|
-rm $(OUT_FLS) $(ML_OUT_FLS)
|
||||||
-rm -r $(DEP_DIR) 2>/dev/null
|
-rm -r $(_DEP_DIR)
|
||||||
|
|
||||||
cleaner:
|
cleaner:
|
||||||
-rm -r $(OUT_DIR)
|
-rm -r $(OUT_DIR)
|
||||||
|
@ -521,9 +521,9 @@ def missing_arg(arg):
|
|||||||
def help():
|
def help():
|
||||||
helpstring = """Synopsis:
|
helpstring = """Synopsis:
|
||||||
Inject <inject-file> into <target-file>:
|
Inject <inject-file> into <target-file>:
|
||||||
python3 html-inect.py --input <input-file> --output <output-file> [OPTIONS]
|
python3 html-inect.py --target <target-file> --output <output-file> [OPTIONS]
|
||||||
\nCommand line options:
|
\nCommand line options:
|
||||||
--input <file> path to the input file
|
--target <file> path to the target file
|
||||||
--output <file> output to this file instead of overwriting target
|
--output <file> output to this file instead of overwriting target
|
||||||
--inplace edit target file in place
|
--inplace edit target file in place
|
||||||
--var <varname>=<value> set the value of a variable. Can be used multiple times
|
--var <varname>=<value> set the value of a variable. Can be used multiple times
|
||||||
@ -543,7 +543,7 @@ if __name__ == "__main__":
|
|||||||
inplace = False
|
inplace = False
|
||||||
i = 1
|
i = 1
|
||||||
while i in range(1, len(argv)):
|
while i in range(1, len(argv)):
|
||||||
if argv[i] == "--input":
|
if argv[i] == "--target":
|
||||||
if len(argv) > i + 1: target_path = argv[i+1].strip(" ")
|
if len(argv) > i + 1: target_path = argv[i+1].strip(" ")
|
||||||
else: missing_arg_val(argv[i])
|
else: missing_arg_val(argv[i])
|
||||||
i += 1
|
i += 1
|
||||||
@ -578,7 +578,7 @@ if __name__ == "__main__":
|
|||||||
error(f"Invalid argument: {argv[i]}")
|
error(f"Invalid argument: {argv[i]}")
|
||||||
i += 1
|
i += 1
|
||||||
# sanity checks
|
# sanity checks
|
||||||
if not target_path: missing_arg("--input")
|
if not target_path: missing_arg("--target")
|
||||||
if not os.path.isfile(target_path): error(f"Invalid target: {target_path} (does not exist)")
|
if not os.path.isfile(target_path): error(f"Invalid target: {target_path} (does not exist)")
|
||||||
if inplace: output_path = target_path
|
if inplace: output_path = target_path
|
||||||
if not output_path:
|
if not output_path:
|
||||||
|
Loading…
Reference in New Issue
Block a user