Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
docs.it4i.cz
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
SCS
docs.it4i.cz
Commits
0e31f6bc
Commit
0e31f6bc
authored
4 weeks ago
by
Lukáš Krupčík
Browse files
Options
Downloads
Patches
Plain Diff
modified: scripts/maketitle.py
parent
d9023adf
No related branches found
Branches containing commit
No related tags found
1 merge request
!486
new file: content/docs/anselm/compute-nodes.mdx
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/maketitle.py
+17
-4
17 additions, 4 deletions
scripts/maketitle.py
with
17 additions
and
4 deletions
scripts/maketitle.py
+
17
−
4
View file @
0e31f6bc
#!/usr/bin/python3
"""
Script to process Markdown files, convert them to MDX,
and add frontmatter based on the first H1 heading.
"""
import
os
import
re
from
pathlib
import
Path
def
process_md_file
(
md_path
):
"""
Converts a Markdown file (.md) to MDX format (.mdx),
adds frontmatter with title from H1 heading, and removes the original file.
Args:
md_path (Path): Path to the Markdown file.
"""
try
:
with
open
(
md_path
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
f
:
content
=
f
.
read
()
with
open
(
md_path
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
f
ile_handle
:
content
=
f
ile_handle
.
read
()
except
UnicodeDecodeError
:
print
(
f
"
Skipping
{
md_path
}
- unable to decode as UTF-8
"
)
return
...
...
@@ -49,14 +61,15 @@ def process_md_file(md_path):
# Create and write MDX file
mdx_path
=
md_path
.
with_suffix
(
'
.mdx
'
)
with
open
(
mdx_path
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
f
.
write
(
new_content
)
with
open
(
mdx_path
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
ile_handle
:
f
ile_handle
.
write
(
new_content
)
# Remove original MD file
md_path
.
unlink
()
print
(
f
"
Converted
{
md_path
}
to
{
mdx_path
}
"
)
def
main
():
"""
Walks through directories and processes all Markdown files.
"""
for
root
,
dirs
,
files
in
os
.
walk
(
'
.
'
):
dirs
[:]
=
[
d
for
d
in
dirs
if
not
d
.
startswith
(
'
.
'
)]
for
file
in
files
:
...
...
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