Skip to content

Commit

Permalink
Merge pull request #845 from EdiWang/feature/svg
Browse files Browse the repository at this point in the history
Support SVG Images
  • Loading branch information
EdiWang authored Nov 20, 2024
2 parents 2ca1329 + 17f5d29 commit dc1bc23
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Moonglade.ImageStorage/ImageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class ImageInfo

public string ImageExtensionName { get; set; }

public string ImageContentType => $"image/{ImageExtensionName}";
public string ImageContentType =>
ImageExtensionName.ToLowerInvariant() == "svg" ?
"image/svg+xml" :
$"image/{ImageExtensionName}";
}
5 changes: 3 additions & 2 deletions src/Moonglade.Web/Controllers/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ImageController(IBlogImageStorage imageStorage,
{
private readonly ImageStorageSettings _imageStorageSettings = imageStorageSettings.Value;

[HttpGet(@"{filename:regex((?!-)([[a-z0-9-]]+)\.(png|jpg|jpeg|gif|bmp|webp))}")]
[HttpGet(@"{filename:regex((?!-)([[a-z0-9-]]+)\.(png|jpg|jpeg|gif|bmp|webp|svg))}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status302Found)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand Down Expand Up @@ -100,7 +100,8 @@ private byte[] AddWatermarkIfNeeded(MemoryStream stream, string ext, bool skipWa
{
if (!blogConfig.ImageSettings.IsWatermarkEnabled || skipWatermark) return null;

if (ext.Equals(".gif", StringComparison.OrdinalIgnoreCase))
if (ext.Equals(".gif", StringComparison.OrdinalIgnoreCase) ||
ext.Equals(".svg", StringComparison.OrdinalIgnoreCase))
{
logger.LogInformation($"Skipped watermark for extension name: {ext}");
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"KnownProxies": []
},
"ImageStorage": {
"AllowedExtensions": [ ".png", ".jpg", ".jpeg", ".gif", ".webp" ],
"AllowedExtensions": [ ".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg" ],
"CacheMinutes": 60,
"Provider": "filesystem",
"FileSystemPath": "C:\\UploadedImages",
Expand Down
1 change: 1 addition & 0 deletions src/Moonglade.Web/wwwroot/js/app/admin.editor.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function loadTinyMCE(textareaSelector) {
document.querySelector('#btn-save').click();
},
paste_data_images: true,
images_file_types: 'png,jpg,jpeg,gif,webp,svg',
images_upload_url: '/image',
images_upload_credentials: true,
extended_valid_elements: 'img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|loading=lazy]',
Expand Down

0 comments on commit dc1bc23

Please sign in to comment.