Implement post editor image drops.
This commit is contained in:
@@ -1119,12 +1119,13 @@ pub fn post_insert_link(slug: &str) -> String {
|
||||
}
|
||||
|
||||
/// Insert a media reference in the editor buffer.
|
||||
/// Returns the Markdown syntax:  or [name](bds-media://id)
|
||||
pub fn post_insert_media(media_id: &str, is_image: bool, original_name: &str) -> String {
|
||||
/// Returns Markdown with a host-absolute media URL suitable for rendered HTML.
|
||||
pub fn post_insert_media(media_path: &str, is_image: bool, original_name: &str) -> String {
|
||||
let url = format!("/{}", media_path.trim_start_matches('/'));
|
||||
if is_image {
|
||||
format!("")
|
||||
format!("")
|
||||
} else {
|
||||
format!("[{original_name}](bds-media://{media_id})")
|
||||
format!("[{original_name}]({url})")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,6 +1178,18 @@ mod tests {
|
||||
assert_eq!(fetched.status, PostStatus::Draft);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inserted_media_uses_host_absolute_renderable_paths() {
|
||||
assert_eq!(
|
||||
post_insert_media("media/2026/07/image.png", true, "image.png"),
|
||||
""
|
||||
);
|
||||
assert_eq!(
|
||||
post_insert_media("/media/2026/07/file.pdf", false, "file.pdf"),
|
||||
"[file.pdf](/media/2026/07/file.pdf)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_post_empty_title_uses_untitled() {
|
||||
let (db, dir) = setup();
|
||||
|
||||
Reference in New Issue
Block a user