Skip to content

Commit c866738

Browse files
committed
Add make commands
1 parent 41ed0fa commit c866738

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

tools/make/lib/markdown/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ include $(TOOLS_MAKE_LIB_DIR)/markdown/assets.mk
2323
include $(TOOLS_MAKE_LIB_DIR)/markdown/equations.mk
2424
include $(TOOLS_MAKE_LIB_DIR)/markdown/namespace_toc.mk
2525
include $(TOOLS_MAKE_LIB_DIR)/markdown/pkg_urls.mk
26+
include $(TOOLS_MAKE_LIB_DIR)/markdown/related.mk

tools/make/lib/markdown/related.mk

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2021 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the path to the remark configuration file:
22+
REMARK_RELATED_CONF ?= $(CONFIG_DIR)/remark/.remarkrc.js
23+
24+
# Define the path to the remark ignore file:
25+
# REMARK_RELATED_IGNORE ?= $(CONFIG_DIR)/remark/.remarkignore FIXME
26+
REMARK_RELATED_IGNORE ?= $(ROOT_DIR)/.remarkignore
27+
28+
# Define the path to a plugin which inserts a "See Also" section of related `stdlib` packages:
29+
REMARK_RELATED_PLUGIN ?= $(TOOLS_PKGS_DIR)/remark/plugins/remark-stdlib-related
30+
REMARK_RELATED_PLUGIN_SETTINGS ?=
31+
REMARK_RELATED_PLUGIN_FLAGS ?= --use $(REMARK_RELATED_PLUGIN)=$(REMARK_RELATED_PLUGIN_SETTINGS)
32+
33+
# Define command-line options when invoking the remark executable:
34+
REMARK_RELATED_FLAGS ?= \
35+
--ext $(MARKDOWN_FILENAME_EXT) \
36+
--rc-path $(REMARK_RELATED_CONF) \
37+
--ignore-path $(REMARK_RELATED_IGNORE)
38+
39+
# Define the remark output option:
40+
REMARK_RELATED_OUTPUT_FLAG ?= --output
41+
42+
43+
# RULES #
44+
45+
#/
46+
# Updates the "See Also" section of Markdown files.
47+
#
48+
# ## Notes
49+
#
50+
# - This rule is useful when wanting to glob for Markdown files (e.g., process all Markdown files for a particular package).
51+
# - In order to insert a list of related `stdlib` packages, a Markdown file must contain a "related" section tag, i.e. <section class="related>.
52+
#
53+
# @param {string} [MARKDOWN_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
54+
# @param {string} [MARKDOWN_PATTERN] - filename pattern (e.g., `*.md`)
55+
#
56+
# @example
57+
# make markdown-related-section
58+
#
59+
# @example
60+
# make markdown-related-section MARKDOWN_PATTERN='README.md' MARKDOWN_FILTER='.*/math/base/special/.*'
61+
#/
62+
markdown-related-section: $(NODE_MODULES)
63+
$(QUIET) $(FIND_MARKDOWN_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
64+
echo ""; \
65+
echo "Processing file: $$file"; \
66+
NODE_PATH="$(NODE_PATH)" \
67+
$(NODE) "$(REMARK)" \
68+
$$file \
69+
$(REMARK_RELATED_FLAGS) \
70+
$(REMARK_RELATED_PLUGIN_FLAGS) \
71+
$(REMARK_RELATED_OUTPUT_FLAG) || exit 1; \
72+
done
73+
74+
.PHONY: markdown-related-section
75+
76+
#/
77+
# Updates the "See Also" section of a specified list of Markdown files.
78+
#
79+
# ## Notes
80+
#
81+
# - This rule is useful when wanting to process a list of Markdown files generated by some other command (e.g., a list of changed Markdown files obtained via `git diff`).
82+
# - In order to insert a list of related `stdlib` packages, a Markdown file must contain a "related" section tag, i.e. <section class="related>.
83+
#
84+
# @param {string} FILES - list of files
85+
#
86+
# @example
87+
# make markdown-related-section-files FILES='/foo/foo.md /foo/bar.md'
88+
#/
89+
markdown-related-section-files: $(NODE_MODULES)
90+
$(QUIET) for file in $(FILES); do \
91+
echo ""; \
92+
echo "Processing file: $$file"; \
93+
NODE_PATH="$(NODE_PATH)" \
94+
$(NODE) "$(REMARK)" \
95+
$$file \
96+
$(REMARK_RELATED_FLAGS) \
97+
$(REMARK_RELATED_PLUGIN_FLAGS) \
98+
$(REMARK_RELATED_OUTPUT_FLAG) || exit 1; \
99+
done
100+
101+
.PHONY: markdown-related-section-files

0 commit comments

Comments
 (0)