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
747a50bb
Commit
747a50bb
authored
4 weeks ago
by
Lukáš Krupčík
Browse files
Options
Downloads
Patches
Plain Diff
fix
parent
25161c91
No related branches found
No related tags found
1 merge request
!486
new file: content/docs/anselm/compute-nodes.mdx
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/url_interni_test.py
+20
-4
20 additions, 4 deletions
scripts/url_interni_test.py
scripts/url_test.py
+4
-1
4 additions, 1 deletion
scripts/url_test.py
with
24 additions
and
5 deletions
scripts/url
-
interni
-
test.py
→
scripts/url
_
interni
_
test.py
+
20
−
4
View file @
747a50bb
...
...
@@ -8,25 +8,41 @@ import re
from
pathlib
import
Path
def
extract_links
(
content
):
"""
Extract all internal links from the file.
"""
"""
Extract all internal links from the file.
:param content: The content of the MDX file.
:return: A list of internal links.
"""
link_pattern
=
re
.
compile
(
r
'
\[.*?\]\((?!http)(.*?)\)
'
)
# Everything except http/https
return
link_pattern
.
findall
(
content
)
def
extract_headers
(
content
):
"""
Extract all H1-H6 headers for hash reference checks.
"""
"""
Extract all H1-H6 headers for hash reference checks.
:param content: The content of the MDX file.
:return: A set of headers formatted as hash links.
"""
header_pattern
=
re
.
compile
(
r
'
^(#+)\s*(.*)
'
,
re
.
MULTILINE
)
return
{
f
"
#
{
match
[
1
].
lower
().
replace
(
'
'
,
'
-
'
)
}
"
for
match
in
header_pattern
.
findall
(
content
)}
def
check_internal_links
(
directory
):
"""
Check the existence of files and hash sections for internal links.
"""
"""
Check the existence of files and hash sections for internal links.
:param directory: The directory containing MDX files.
"""
mdx_files
=
{
f
.
relative_to
(
directory
):
f
for
f
in
Path
(
directory
).
rglob
(
"
*.mdx
"
)}
file_headers
=
{}
# Extract headers from each file
for
mdx_file
,
path
in
mdx_files
.
items
():
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
content
=
file
.
read
()
file_headers
[
mdx_file
]
=
extract_headers
(
content
)
# Check internal links
for
mdx_file
,
path
in
mdx_files
.
items
():
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
content
=
file
.
read
()
...
...
@@ -44,7 +60,7 @@ def check_internal_links(directory):
print
(
f
"
❌ Broken file link in
{
mdx_file
}
:
{
link
}
"
)
# Check if the section exists
elif
hash_part
and
hash_part
not
in
file_headers
.
get
(
file_part
,
{}
):
elif
hash_part
and
hash_part
not
in
file_headers
.
get
(
file_part
,
set
()
):
print
(
f
"
⚠️ Broken section link in
{
mdx_file
}
:
{
link
}
"
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
scripts/url
-
test.py
→
scripts/url
_
test.py
+
4
−
1
View file @
747a50bb
...
...
@@ -26,7 +26,10 @@ def check_links_in_mdx(directory):
try
:
response
=
requests
.
head
(
link
,
allow_redirects
=
True
,
timeout
=
5
)
if
response
.
status_code
>=
400
:
print
(
f
"
❌ Broken link in
{
mdx_file
}
:
{
link
}
(Status:
{
response
.
status_code
}
)
"
)
print
(
f
"
❌ Broken link in
{
mdx_file
}
:
{
link
}
"
f
"
(Status:
{
response
.
status_code
}
)
"
)
except
requests
.
RequestException
:
print
(
f
"
⚠️ Error checking
{
link
}
in
{
mdx_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