Skip to content

Commit f836da8

Browse files
authored
Merge pull request #323 from dwrolvink/master
add file export util
2 parents f63ec2f + f689be6 commit f836da8

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed
991 Bytes
Binary file not shown.

dist/obsidianhtml-3.1.0.tar.gz

175 Bytes
Binary file not shown.

obsidianhtml/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,4 +927,39 @@ def main():
927927
feed.Compile()
928928
print('< COMPILING RSS FEED: Done')
929929

930+
if pb.gc('file_exports'):
931+
file_exports = pb.gc('file_exports')
932+
if not isinstance(file_exports, list):
933+
raise Exception(f'Config value type of file_exports should be list, instead of {type(file_exports).__name__}.')
934+
935+
print('> EXPORTING USER FILES')
936+
937+
for ufile in file_exports:
938+
939+
src = pb.paths['obsidian_folder'].joinpath(ufile['src']).resolve()
940+
dst = pb.paths['html_output_folder'].joinpath(ufile['dst']).resolve()
941+
if not src.exists():
942+
raise Exception(f'File {src.as_posix()} not found')
943+
944+
if 'encoding' not in ufile:
945+
encoding = 'utf-8'
946+
else:
947+
encoding = ufile['encoding']
948+
949+
print(f"\tWriting {src.as_posix()} to {dst.as_posix()} ({encoding})")
950+
951+
if encoding == 'binary':
952+
with open(src, 'rb') as f:
953+
contents = f.read()
954+
with open (dst, 'wb') as f:
955+
f.write(contents)
956+
else:
957+
with open(src, 'r', encoding=encoding) as f:
958+
contents = f.read()
959+
with open(dst, 'w', encoding=encoding) as f:
960+
f.write(contents)
961+
962+
print('< EXPORTING USER FILES: Done')
963+
964+
930965

obsidianhtml/src/defaults_config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ html_custom_footer_inclusions: []
8383

8484
navbar_links: []
8585

86+
file_exports: []
87+
# file_exports:
88+
# - encoding: binary
89+
# src: Resources/Includes/favicon.ico
90+
# dst: favicon.ico
91+
# - src: Resources/Includes/christmas_snowflakes.js
92+
# dst: obs.html/static/christmas_snowflakes.js
93+
8694
##########################################################################
8795
# OPTIONAL BEHAVIOR / FEATURES #
8896
##########################################################################

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = obsidianhtml
3-
version = 3.1.0
3+
version = 3.2.0
44
summary = Converts Obsidian notes into proper markdown and HTML
55
long_description = file: pypi_readme.md
66
home_page = https://github.com/obsidian-html/obsidian-html

0 commit comments

Comments
 (0)