Skip to content

Commit 9f40f0e

Browse files
Merge pull request #294 from adamtheturtle/svg
Add workaround for SVG error with Ultimate Notion
2 parents ef5bb24 + 1b7ed89 commit 9f40f0e

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
*.mp3 filter=lfs diff=lfs merge=lfs -text
66
*.mp4 filter=lfs diff=lfs merge=lfs -text
77
*.wav filter=lfs diff=lfs merge=lfs -text
8+
*.svg filter=lfs diff=lfs merge=lfs -text
89
* text=auto eol=lf

sample/_static/camera.svg

Lines changed: 3 additions & 0 deletions
Loading

sample/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,3 +1622,8 @@ The builder supports task lists with checkboxes:
16221622
- [ ] Another bullet point.
16231623

16241624
3. [ ] Task C
1625+
1626+
SVG support
1627+
~~~~~~~~~~~
1628+
1629+
.. image:: _static/camera.svg

sample/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ callout
22
checkboxes
33
reStructuredText
44
Schrödinger
5+
SVG

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CLI
2+
SVG
23
backtick
34
backticks
45
callout

src/_notion_scripts/upload.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import hashlib
77
import json
8+
import mimetypes
89
from enum import Enum
910
from functools import cache
1011
from pathlib import Path
@@ -150,10 +151,18 @@ def _block_from_details(
150151
# across Python versions and platforms.
151152
file_path = Path(url2pathname(parsed.path)) # type: ignore[misc]
152153

154+
# Ultimate Notion does not support SVG files, so we need to
155+
# provide the MIME type ourselves for SVG files.
156+
# See https://github.com/ultimate-notion/ultimate-notion/issues/141.
157+
mime_type, _ = mimetypes.guess_type(url=file_path.name)
158+
if mime_type != "image/svg+xml":
159+
mime_type = None
160+
153161
with file_path.open(mode="rb") as file_stream:
154162
uploaded_file = session.upload(
155163
file=file_stream,
156164
file_name=file_path.name,
165+
mime_type=mime_type,
157166
)
158167

159168
uploaded_file.wait_until_uploaded()

0 commit comments

Comments
 (0)