Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0893767

Browse files
authored
run: node UpdateDirectory.js
1 parent 856ec1b commit 0893767

File tree

1 file changed

+2
-50
lines changed

1 file changed

+2
-50
lines changed

‎.github/workflows/update_directory_md.yml‎

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,8 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@master
9-
- uses: actions/setup-python@master
10-
- name: update_directory_md
11-
shell: python
12-
run: |
13-
import os
14-
from typing import Iterator
15-
16-
URL_BASE = "https://github.com/TheAlgorithms/Javascript/blob/master"
17-
g_output = []
18-
19-
20-
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
21-
for dirpath, dirnames, filenames in os.walk(top_dir):
22-
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
23-
for filename in filenames:
24-
if os.path.splitext(filename)[1].lower() == ".js":
25-
yield os.path.join(dirpath, filename).lstrip("./")
26-
27-
28-
def md_prefix(i):
29-
return f"{i * ' '}*" if i else "\n##"
30-
31-
32-
def print_path(old_path: str, new_path: str) -> str:
33-
global g_output
34-
old_parts = old_path.split(os.sep)
35-
for i, new_part in enumerate(new_path.split(os.sep)):
36-
if i + 1 > len(old_parts) or old_parts[i] != new_part:
37-
if new_part:
38-
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ')}")
39-
return new_path
40-
41-
42-
def build_directory_md(top_dir: str = ".") -> str:
43-
global g_output
44-
old_path = ""
45-
for filepath in sorted(good_filepaths(), key=str.lower):
46-
filepath, filename = os.path.split(filepath)
47-
if filepath != old_path:
48-
old_path = print_path(old_path, filepath)
49-
indent = (filepath.count(os.sep) + 1) if filepath else 0
50-
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
51-
filename = os.path.splitext(filename.replace("_", " "))[0]
52-
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
53-
return "\n".join(g_output)
54-
55-
56-
with open("DIRECTORY.md", "w") as out_file:
57-
out_file.write(build_directory_md(".") + "\n")
58-
9+
- uses: actions/setup-node@v1
10+
- run: node UpdateDirectory.js
5911
- name: Update DIRECTORY.md
6012
run: |
6113
cat DIRECTORY.md

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /