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
de252ca2
Verified
Commit
de252ca2
authored
5 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
cleaning up the script to generate headers
parent
0104d3b6
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
+12
-6
12 additions, 6 deletions
generateIndex.py
with
12 additions
and
6 deletions
generateIndex.py
+
12
−
6
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
(
"
-----------------------
"
)
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