commit 865acdcfaa3421db3250fa1ba4d8ca38623c4a8e
parent dddf609197f77ac3b24d403f384b1b9fc8c03911
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 26 Oct 2024 16:42:41 +0200
feat: use URL as note name before falling back to shasum
Diffstat:
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/helpers.php b/lib/helpers.php
@@ -153,11 +153,20 @@ function generate_filename(string $content) {
$filename = page_title($file_link);
}
- /* if filename is still unset after this
- * (file did not contain link OR fetching page title failed)
- * we use the sha256sum of the content as fallback name */
+ /* if filename is still unset after this and does have a link,
+ * (so the fetching failed), we can use the link itself as title.
+ * if the content does NOT contain a link, we use the sha256sum of the
+ * content as fallback name */
if (empty($filename)) {
- $filename = hash("sha256", $content, false);
+ if (!empty($file_link)) {
+ $filename = preg_replace(
+ '/http(s){0,1}:\/\/(.*)/',
+ '\1',
+ $file_link
+ );
+ } else {
+ $filename = hash("sha256", $content, false);
+ }
}
/* Ensure the new filename only contains valid characters */