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
25161c91
Commit
25161c91
authored
1 month ago
by
Lukáš Krupčík
Browse files
Options
Downloads
Patches
Plain Diff
modified: scripts/url-interni-test.py
modified: scripts/url-test.py
parent
f697f03b
No related branches found
Branches containing commit
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
+18
-14
18 additions, 14 deletions
scripts/url-interni-test.py
scripts/url-test.py
+17
-7
17 additions, 7 deletions
scripts/url-test.py
with
35 additions
and
21 deletions
scripts/url-interni-test.py
+
18
−
14
View file @
25161c91
#!/bin/python3
#!/usr/bin/python3
"""
Script to check internal links and section references in MDX files.
"""
import
re
import
re
from
pathlib
import
Path
from
pathlib
import
Path
def
extract_links
(
content
):
def
extract_links
(
content
):
"""
Extra
huje všechny interní odkazy ze souboru.
"""
"""
Extra
ct all internal links from the file.
"""
link_pattern
=
re
.
compile
(
r
'
\[.*?\]\((?!http)(.*?)\)
'
)
#
Vše kromě
http/https
link_pattern
=
re
.
compile
(
r
'
\[.*?\]\((?!http)(.*?)\)
'
)
#
Everything except
http/https
return
link_pattern
.
findall
(
content
)
return
link_pattern
.
findall
(
content
)
def
extract_headers
(
content
):
def
extract_headers
(
content
):
"""
Extra
huje všechna H1-H6 nadpisy pro kontrolu hash odkazů.
"""
"""
Extra
ct all H1-H6 headers for hash reference checks.
"""
header_pattern
=
re
.
compile
(
r
'
^(#+)\s*(.*)
'
,
re
.
MULTILINE
)
header_pattern
=
re
.
compile
(
r
'
^(#+)\s*(.*)
'
,
re
.
MULTILINE
)
return
{
f
"
#
{
h
[
1
].
lower
().
replace
(
'
'
,
'
-
'
)
}
"
:
h
[
1
]
for
h
in
header_pattern
.
findall
(
content
)}
return
{
f
"
#
{
matc
h
[
1
].
lower
().
replace
(
'
'
,
'
-
'
)
}
"
for
matc
h
in
header_pattern
.
findall
(
content
)}
def
check_internal_links
(
directory
):
def
check_internal_links
(
directory
):
"""
Kontroluje existenci souborů a hash sekcí pro interní odkazy.
"""
"""
Check the existence of files and hash sections for internal links.
"""
mdx_files
=
{
f
.
relative_to
(
directory
):
f
for
f
in
Path
(
directory
).
rglob
(
"
*.mdx
"
)}
mdx_files
=
{
f
.
relative_to
(
directory
):
f
for
f
in
Path
(
directory
).
rglob
(
"
*.mdx
"
)}
file_headers
=
{}
file_headers
=
{}
for
mdx_file
,
path
in
mdx_files
.
items
():
for
mdx_file
,
path
in
mdx_files
.
items
():
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
ile
:
content
=
f
.
read
()
content
=
f
ile
.
read
()
file_headers
[
mdx_file
]
=
extract_headers
(
content
)
file_headers
[
mdx_file
]
=
extract_headers
(
content
)
for
mdx_file
,
path
in
mdx_files
.
items
():
for
mdx_file
,
path
in
mdx_files
.
items
():
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
with
open
(
path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
ile
:
content
=
f
.
read
()
content
=
f
ile
.
read
()
links
=
extract_links
(
content
)
links
=
extract_links
(
content
)
for
link
in
links
:
for
link
in
links
:
...
@@ -35,13 +39,13 @@ def check_internal_links(directory):
...
@@ -35,13 +39,13 @@ def check_internal_links(directory):
file_target
=
(
Path
(
mdx_file
).
parent
/
file_part
).
resolve
()
file_target
=
(
Path
(
mdx_file
).
parent
/
file_part
).
resolve
()
#
Kontrola existence souboru
#
Check if the file exists
if
file_part
and
file_target
not
in
mdx_files
.
values
():
if
file_part
and
file_target
not
in
mdx_files
.
values
():
print
(
f
"
❌ Broken file link in
{
mdx_file
}
:
{
link
}
"
)
print
(
f
"
❌ Broken file link in
{
mdx_file
}
:
{
link
}
"
)
#
Kontrola existence sekce
#
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
,
{}):
print
(
f
"
⚠️ Broken section link in
{
mdx_file
}
:
{
link
}
"
)
print
(
f
"
⚠️ Broken section link in
{
mdx_file
}
:
{
link
}
"
)
check_internal_links
(
"
content/docs
"
)
if
__name__
==
"
__main__
"
:
check_internal_links
(
"
content/docs
"
)
This diff is collapsed.
Click to expand it.
scripts/url-test.py
+
17
−
7
View file @
25161c91
#!/bin/python3
#!/usr/bin/python3
"""
Script to check external links in MDX files.
"""
import
re
import
re
import
requests
from
pathlib
import
Path
from
pathlib
import
Path
import
requests
def
check_links_in_mdx
(
directory
):
def
check_links_in_mdx
(
directory
):
"""
Scans MDX files in the given directory for external links and checks their availability.
:param directory: Path to the directory containing MDX files.
"""
mdx_files
=
Path
(
directory
).
rglob
(
"
*.mdx
"
)
mdx_files
=
Path
(
directory
).
rglob
(
"
*.mdx
"
)
url_pattern
=
re
.
compile
(
r
'
\[.*?\]\((http[s]?://.*?)\)
'
)
url_pattern
=
re
.
compile
(
r
'
\[.*?\]\((http[s]?://.*?)\)
'
)
for
mdx_file
in
mdx_files
:
for
mdx_file
in
mdx_files
:
with
open
(
mdx_file
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
with
open
(
mdx_file
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
ile
:
content
=
f
.
read
()
content
=
f
ile
.
read
()
links
=
url_pattern
.
findall
(
content
)
links
=
url_pattern
.
findall
(
content
)
for
link
in
links
:
for
link
in
links
:
try
:
try
:
response
=
requests
.
head
(
link
,
allow_redirects
=
True
,
timeout
=
5
)
response
=
requests
.
head
(
link
,
allow_redirects
=
True
,
timeout
=
5
)
if
response
.
status_code
>=
400
:
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
}
(Status:
{
response
.
status_code
}
)
"
)
except
requests
.
RequestException
:
except
requests
.
RequestException
:
print
(
f
"
Error checking
{
link
}
in
{
mdx_file
}
"
)
print
(
f
"
⚠️
Error checking
{
link
}
in
{
mdx_file
}
"
)
check_links_in_mdx
(
"
content/docs
"
)
if
__name__
==
"
__main__
"
:
check_links_in_mdx
(
"
content/docs
"
)
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