Skip to content

Commit f050558

Browse files
authored
feat: adding includeExt option
1 parent 95080bb commit f050558

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ It creates a list of each markdown file in the folders and displays it under doc
1111

1212
## Inputs
1313

14-
| Parameters | Optional | Description |
15-
| -------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
16-
| `folder` || The folder path to start at, default uses `${{github.workspace}}` |
17-
| `filename` || The filename of the generated file. default to `index` |
18-
| `content-file` || The filepath (relative to where the README.md or index.md) where content will be read from and input into index file, default to `.content.md` |
19-
| `include` || The files to additionaly include in the index file, follows glob pattern on the filenames, supports multiple patterns via multi-line string` |
20-
| `exclude` || The files to exclude from the index file, follows glob pattern on the filenames, supports multiple patterns via multi-line string |
14+
| Parameters | Optional | Description |
15+
| -------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
16+
| `folder` || The folder path to start at, default uses `${{github.workspace}}` |
17+
| `filename` || The filename of the generated file. default to `index` |
18+
| `content-file` || The filepath (relative to where the README.md or index.md) where content will be read from and input into index file, default to `.content.md` |
19+
| `include` || The files to additionaly include in the index file, follows glob pattern on the filenames, supports multiple patterns via multi-line string` |
20+
| `exclude` || The files to exclude from the index file, follows glob pattern on the filenames, supports multiple patterns via multi-line string |
21+
| `includeExt` || Whenever or not to include extensions in the documents text |
2122

2223
## Examples
2324

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
description: The files to exclude from the index file, follows glob pattern on the filenames, supports multiple patterns via multi-line string
2525
required: false
2626
default: ""
27+
includeExt:
28+
description: Whether to include the file extension in the index file links
29+
required: false
30+
default: "false"
2731
runs:
2832
using: "node20"
2933
main: "dist/index.js"

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Processor } from "./traverse";
22
import {
33
debug,
44
error,
5+
getBooleanInput,
56
getInput,
67
getMultilineInput,
78
setFailed,
@@ -14,15 +15,14 @@ try {
1415
// This should be a token with access to your repository scoped in as a secret.
1516
// The YML workflow will need to set myToken with the GitHub Secret Token
1617
// token: ${{ secrets.GITHUB_TOKEN }}
17-
18-
const args: Arguments = {
18+
const args = Arguments.sanitize({
1919
contentFilename: getInput("content"),
2020
excludes: getMultilineInput("exclude"),
2121
includes: getMultilineInput("include"),
2222
indexFilename: getInput("filename"),
2323
startFolder: getInput("folder"),
24-
};
25-
Arguments.sanitize(args);
24+
includeExt: getBooleanInput("includeExt"),
25+
});
2626

2727
info("starting on: " + args.startFolder);
2828
debug(`arguments ${JSON.stringify(args, undefined, 2)}`);

src/arguments.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export class Arguments {
55
startFolder: string;
66
/** The filename of the index files */
77
indexFilename: string;
8+
/** Whether to include the file extension in the links */
9+
includeExt: boolean;
810
/** The content filename to add to indexes */
911
contentFilename: string;
1012
/** The patterns to include, addeds *.md by default */
@@ -14,7 +16,7 @@ export class Arguments {
1416
}
1517

1618
export namespace Arguments {
17-
export function sanitize(args: Arguments): void {
19+
export function sanitize(args: Arguments): Arguments {
1820
// Checks
1921
if (args.startFolder === "") {
2022
throw new Error("No folder specified");
@@ -38,8 +40,15 @@ export namespace Arguments {
3840
if (args.contentFilename !== "") {
3941
args.excludes.push(args.contentFilename);
4042
}
43+
if (args.includeExt === undefined) {
44+
args.includeExt = false;
45+
}
46+
if (typeof args.includeExt === "string") {
47+
args.includeExt = args.includeExt === "true";
48+
}
4149

4250
args.includes.push("*.md");
4351
args.excludes.push(args.indexFilename, ".git", "node_modules");
52+
return args;
4453
}
4554
}

src/traverse.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import path from "path";
1010
import { Arguments } from "./arguments";
1111
import { FileFilter } from "./filter";
12-
import { debug, info } from "@actions/core";
12+
import { info } from "@actions/core";
1313

1414
const Template = `# {$HEADER$}
1515
{$CONTENT$}
@@ -73,7 +73,13 @@ export class Processor {
7373

7474
//If the child is a .md page create a reference
7575
} else if (this.includeFile(child)) {
76-
const linkName = child.substring(0, child.length - 3);
76+
let linkName = child;
77+
if (!this.options.includeExt) {
78+
const lastIndex = child.lastIndexOf(".");
79+
if (lastIndex > 0) {
80+
linkName = child.substring(0, lastIndex);
81+
}
82+
}
7783
const fileUrl = encodeURI(child);
7884

7985
documents.push(`- [${linkName}](${fileUrl})`);

0 commit comments

Comments
 (0)