Skip to content

Commit 0bb7af3

Browse files
committed
build: update markdown-to-html to avoid output conflicts
With the new `ts_project`, or `ng_project` rule, HTML templates of components are also copied over to the bazel bin. This unveiled a naming conflict of e.g. `slider.md` being generated as `slider.html`; while there is a template like `slider.html`.
1 parent b5d4de9 commit 0bb7af3

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

material.angular.io/src/app/pages/component-viewer/component-viewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class ComponentOverview extends ComponentBaseView {
168168
// folder named after the component while the overview file is named similarly. e.g.
169169
// `cdk#overlay` -> `cdk/overlay/overlay.md`
170170
// `material#button` -> `material/button/button.md`
171-
const overviewPath = doc.overviewPath || `${doc.packageName}/${doc.id}/${doc.id}.html`;
171+
const overviewPath = doc.overviewPath || `${doc.packageName}/${doc.id}/${doc.id}.md.html`;
172172
return `/docs-content/overviews/${overviewPath}`;
173173
}
174174
}

tools/markdown-to-html/index.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def _markdown_to_html(ctx):
3030
for input_file in input_files:
3131
# Determine the input file path relatively to the current package path. This is necessary
3232
# because we want to preserve directories for the input files and `declare_file` expects a
33-
# path that is relative to the current package. Also note that we should not use `.replace`
34-
# here because the extension can be also in upper case.
35-
relative_basepath = _relative_to_label(ctx.label, input_file.short_path)[:-len(".md")]
33+
# path that is relative to the current package.
34+
relative_basepath = _relative_to_label(ctx.label, input_file.short_path)
3635

37-
# For each input file "xxx.md", we want to write an output file "xxx.html"
38-
expected_outputs += [ctx.actions.declare_file("%s.html" % relative_basepath)]
36+
# For each input file "xxx.md", we want to write an output file "xxx.md.html"
37+
# Note: we preserve the `.md` text to avoid collisions with real templates.
38+
expected_outputs.append(ctx.actions.declare_file("%s.html" % relative_basepath))
3939

4040
# Add the input file to the command line arguments that will be passed to the
4141
# transform-markdown executable.
@@ -69,7 +69,7 @@ markdown_to_html = rule(
6969
"_transform_markdown": attr.label(
7070
default = Label("//tools/markdown-to-html"),
7171
executable = True,
72-
cfg = "host",
72+
cfg = "exec",
7373
),
7474
},
7575
)

tools/markdown-to-html/transform-markdown.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import {join} from 'path';
99
import {highlightCodeBlock} from '../highlight-files/highlight-code-block';
1010
import {DocsMarkdownRenderer} from './docs-marked-renderer';
1111

12-
// Regular expression that matches the markdown extension of a given path.
13-
const markdownExtension = /.md$/;
14-
1512
// Custom markdown renderer for transforming markdown files for the docs.
1613
const markdownRenderer = new DocsMarkdownRenderer();
1714

@@ -26,7 +23,7 @@ if (require.main === module) {
2623
// Walk through each input file and write transformed markdown output to the specified
2724
// Bazel bin directory.
2825
inputFiles.forEach(inputPath => {
29-
const outputPath = join(bazelBinPath, inputPath.replace(markdownExtension, '.html'));
26+
const outputPath = join(bazelBinPath, `${inputPath}.html`);
3027
const htmlOutput = markdownRenderer.finalizeOutput(
3128
marked(readFileSync(inputPath, 'utf8')),
3229
inputPath,

0 commit comments

Comments
 (0)