Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
R3
howto-cards
Commits
de252ca2
Verified
Commit
de252ca2
authored
Feb 17, 2020
by
Laurent Heirendt
✈
Browse files
cleaning up the script to generate headers
parent
0104d3b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
generateIndex.py
View file @
de252ca2
...
...
@@ -27,7 +27,6 @@ def remove_header(localroot, root, filename, n=5):
# check if the header is actually a header
if
(
count
==
0
or
count
==
n
)
and
line
[
0
:
3
]
==
"---"
:
print
(
"existing header detected: "
+
line
[
0
:
2
]
)
headerCheck
=
True
# remove the header
...
...
@@ -40,7 +39,7 @@ def remove_header(localroot, root, filename, n=5):
os
.
remove
(
filename
)
os
.
rename
(
"tmp"
+
filename
,
filename
)
print
(
"
H
eader removed
: "
+
filename
)
print
(
"
- Old h
eader removed
."
)
# change back to the local root
os
.
chdir
(
localroot
)
...
...
@@ -53,10 +52,11 @@ for root, dirs, files in os.walk(folder):
for
file
in
files
:
if
file
.
endswith
(
".md"
):
fileName
=
os
.
path
.
join
(
root
,
file
)
#ignore subsections
#ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"_"
:
#
print(
localroot
)
print
(
"root: "
+
root
+
" file: "
+
file
)
print
(
" > Generating header for: "
+
fileName
)
# remove the previous header
remove_header
(
localroot
,
root
,
file
,
8
)
...
...
@@ -69,8 +69,10 @@ for root, dirs, files in os.walk(folder):
# remove the first /
shortcut
=
shortcut
[
1
:]
# replace the / with a :
shortcut
=
re
.
sub
(
'/'
,
':'
,
shortcut
)
# define the header for each card
header
=
"---
\n
"
header
+=
"layout: page
\n
"
header
+=
"permalink: "
+
permalink
+
"
\n
"
...
...
@@ -80,5 +82,9 @@ for root, dirs, files in os.walk(folder):
header
+=
" - /internal/cards/"
+
shortcut
+
"
\n
"
header
+=
"---"
#
print(header)
#
add the header properly speaking
line_prepender
(
fileName
,
header
)
# output
print
(
" + New header added."
)
print
(
"-----------------------"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment