Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
5c0015cd
"src/git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "797ed9ac7f5590bd0358e55f632ec5f729873d21"
Commit
5c0015cd
authored
Jun 23, 2024
by
Timothy J. Baek
Browse files
fix: frontmatter
parent
abf212c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
backend/apps/webui/utils.py
backend/apps/webui/utils.py
+25
-10
No files found.
backend/apps/webui/utils.py
View file @
5c0015cd
...
@@ -10,17 +10,32 @@ def extract_frontmatter(file_path):
...
@@ -10,17 +10,32 @@ def extract_frontmatter(file_path):
Extract frontmatter as a dictionary from the specified file path.
Extract frontmatter as a dictionary from the specified file path.
"""
"""
frontmatter
=
{}
frontmatter
=
{}
frontmatter_pattern
=
re
.
compile
(
r
"^([a-z_]+):\s*(.*)\s*$"
,
re
.
IGNORECASE
)
frontmatter_started
=
False
frontmatter_ended
=
False
frontmatter_pattern
=
re
.
compile
(
r
"^\s*([a-z_]+):\s*(.*)\s*$"
,
re
.
IGNORECASE
)
with
open
(
file_path
,
"r"
,
encoding
=
"utf-8"
)
as
file
:
try
:
for
line
in
file
:
with
open
(
file_path
,
"r"
,
encoding
=
"utf-8"
)
as
file
:
if
line
.
strip
()
==
'"""'
:
for
line
in
file
:
# End of frontmatter section
if
'"""'
in
line
:
break
if
not
frontmatter_started
:
match
=
frontmatter_pattern
.
match
(
line
)
frontmatter_started
=
True
if
match
:
continue
# skip the line with the opening triple quotes
key
,
value
=
match
.
groups
()
else
:
frontmatter
[
key
]
=
value
frontmatter_ended
=
True
break
if
frontmatter_started
and
not
frontmatter_ended
:
match
=
frontmatter_pattern
.
match
(
line
)
if
match
:
key
,
value
=
match
.
groups
()
frontmatter
[
key
.
strip
()]
=
value
.
strip
()
except
FileNotFoundError
:
print
(
f
"Error: The file
{
file_path
}
does not exist."
)
return
{}
except
Exception
as
e
:
print
(
f
"An error occurred:
{
e
}
"
)
return
{}
return
frontmatter
return
frontmatter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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