Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
howto-cards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marie Fossepre
howto-cards
Commits
3fe4b5c0
Verified
Commit
3fe4b5c0
authored
5 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
WIP: writing index
parent
de252ca2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
generateIndex.py
+41
-2
41 additions, 2 deletions
generateIndex.py
with
41 additions
and
2 deletions
generateIndex.py
+
41
−
2
View file @
3fe4b5c0
import
os
,
re
folder
=
"
external
"
def
line_prepender
(
filename
,
line
):
with
open
(
filename
,
'
r+
'
)
as
f
:
content
=
f
.
read
()
...
...
@@ -46,14 +48,13 @@ def remove_header(localroot, root, filename, n=5):
#print("exit folder:" + os.getcwd())
# loop through the entire internal tree
folder
=
"
external
"
localroot
=
os
.
getcwd
()
for
root
,
dirs
,
files
in
os
.
walk
(
folder
):
for
file
in
files
:
if
file
.
endswith
(
"
.md
"
):
fileName
=
os
.
path
.
join
(
root
,
file
)
#ignore subsections (.md files that start with _)
#
ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"
_
"
:
print
(
"
> Generating header for:
"
+
fileName
)
...
...
@@ -85,6 +86,44 @@ for root, dirs, files in os.walk(folder):
# add the header properly speaking
line_prepender
(
fileName
,
header
)
#print(permalink)
# output
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
# generate the index properly speaking
dirs
=
os
.
listdir
(
folder
)
dirs
=
sorted
(
dirs
)
for
d
in
dirs
:
print
(
"
###
"
+
d
.
capitalize
())
for
root
,
dirs
,
files
in
os
.
walk
(
folder
+
"
/
"
+
d
):
for
file
in
files
:
if
file
.
endswith
(
"
.md
"
):
fileName
=
os
.
path
.
join
(
root
,
file
)
# ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"
_
"
:
# remove ./ from root
#print(" > Adding " + fileName + " to index ...")
# open file and get the title after the header
count
=
0
title
=
""
with
open
(
fileName
,
'
r
'
)
as
f
:
for
line
in
f
:
count
+=
1
if
count
==
9
:
title
=
line
break
# remove first and last chars
title
=
title
.
rstrip
(
"
\n\r
"
)
title
=
title
[
2
:]
print
(
"
* [
"
+
title
+
"
](./
"
+
root
+
"
/
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment