Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
R3
howto-cards
Commits
4248b6de
Verified
Commit
4248b6de
authored
Feb 18, 2020
by
Laurent Heirendt
✈
Browse files
avoid hidden folders
parent
340c51d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
.ci/generateIndex.py
View file @
4248b6de
import
os
,
re
folder
=
"
ex
ternal"
folder
=
"
in
ternal"
def
line_prepender
(
filename
,
line
):
with
open
(
filename
,
'r+'
)
as
f
:
...
...
@@ -58,72 +58,73 @@ index = ""
for
d
in
dirs
:
# set the header of the section
index
+=
"
\n
### "
+
d
.
replace
(
"-"
,
" "
).
capitalize
()
+
"
\n
"
localIndexArr
=
[
"
\n
"
]
# walk through the folders with all the cards
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
]
!=
"_"
:
print
(
" > Generating header for: "
+
fileName
)
# remove the previous header
remove_header
(
localroot
,
root
,
file
,
8
)
# generate a permalink
permalink
=
"/"
+
root
+
"/"
# generate the shortcut
shortcut
=
re
.
sub
(
folder
,
''
,
root
)
# 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
"
header
+=
"shortcut: "
+
shortcut
+
"
\n
"
header
+=
"redirect_from:
\n
"
header
+=
" - /cards/"
+
shortcut
+
"
\n
"
header
+=
" - /internal/cards/"
+
shortcut
+
"
\n
"
header
+=
"---"
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# 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
:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr
.
append
(
"* ["
+
title
+
"](./"
+
root
+
"/"
+
")
\n
"
)
# output
print
(
" + New header added."
)
print
(
"-----------------------"
)
# join all subcategories to the index
localIndexArr
.
sort
()
index
+=
''
.
join
(
localIndexArr
)
if
d
[
0
]
!=
"."
:
# set the header of the section
index
+=
"
\n
### "
+
d
.
replace
(
"-"
,
" "
).
capitalize
()
+
"
\n
"
localIndexArr
=
[
"
\n
"
]
# walk through the folders with all the cards
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
]
!=
"_"
:
print
(
" > Generating header for: "
+
fileName
)
# remove the previous header
remove_header
(
localroot
,
root
,
file
,
8
)
# generate a permalink
permalink
=
"/"
+
root
+
"/"
# generate the shortcut
shortcut
=
re
.
sub
(
folder
,
''
,
root
)
# 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
"
header
+=
"shortcut: "
+
shortcut
+
"
\n
"
header
+=
"redirect_from:
\n
"
header
+=
" - /cards/"
+
shortcut
+
"
\n
"
header
+=
" - /internal/cards/"
+
shortcut
+
"
\n
"
header
+=
"---"
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# 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
:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr
.
append
(
"* ["
+
title
+
"](./"
+
root
+
"/"
+
")
\n
"
)
# output
print
(
" + New header added."
)
print
(
"-----------------------"
)
# join all subcategories to the index
localIndexArr
.
sort
()
index
+=
''
.
join
(
localIndexArr
)
# output the index
#print(index)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment