# HG changeset patch # User Ludovic Chabant # Date 1531281838 25200 # Node ID be74ba54a06f56833a2b9d3f677833473cb59964 # Parent 0aeb6f18d6a0a5f53d17dfc11fb3d189ed12eec4 admin: Improvements to micropub endpoint's photo handling. - Add `.jpg` extension to photos that don't have any extension. - Add photos in the config section instead of the body, so that the layout can put them in separate `u-photo` tags. diff -r 0aeb6f18d6a0 -r be74ba54a06f piecrust/admin/views/micropub.py --- a/piecrust/admin/views/micropub.py Tue Jul 10 21:01:45 2018 -0700 +++ b/piecrust/admin/views/micropub.py Tue Jul 10 21:03:58 2018 -0700 @@ -98,6 +98,9 @@ fn = re_unsafe_asset_char.sub('_', fn) fn = '%s_%s' % (uuid.uuid1().hex, fn) fn = fn.rstrip('_') + _, fnext = os.path.splitext(fn) + if not fnext: + fn = fn + '.jpg' photo_cache_dir = os.path.join( g.site.root_dir, @@ -302,7 +305,7 @@ paths_to_commit.append(p_thumb_path) p_thumb_no_ext = '%s_thumb' % p_fn_no_ext - photo_names.append((p_thumb_no_ext, p_fn_no_ext)) + photo_names.append((p_fn_no_ext, p_thumb_no_ext)) else: photo_names.append((p_fn_no_ext, None)) @@ -354,9 +357,18 @@ paths_to_commit.append(content_item.spec) with source.openItem(content_item, mode='w', encoding='utf8') as fp: fp.write('---\n') + yaml.dump(post_config, fp, default_flow_style=False, allow_unicode=True) + + if photo_names: + fp.write('photos:\n') + for pfull, pthumb in photo_names: + fp.write('- name: %s\n' % pfull) + if pthumb: + fp.write(' thumb: %s\n' % pthumb) + fp.write('---\n') if summary: @@ -365,18 +377,6 @@ fp.write('\n\n') fp.write(content) - if photo_names: - fp.write('\n\n') - for pthumb, pfull in photo_names: - if pfull: - fp.write('' - '%s' - '\n\n' % - (pfull, pthumb, pthumb)) - else: - fp.write('%s\n\n' % - (pthumb, pthumb)) - if os.supports_fd: import stat try: