Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of empty markdown or missing meta-data #120

Merged
merged 1 commit into from Oct 15, 2014

Conversation

@kfricke-hacon
Copy link
Contributor

@kfricke-hacon kfricke-hacon commented Oct 13, 2014

Respect markdown files which do not contain any meta-data.

Respect markdown files which do not contain any meta-data.
@saimn
Copy link
Owner

@saimn saimn commented Oct 14, 2014

Hi,
I fail to reproduce an error with this code, could you give more details ?
Thanks

@kfricke-hacon
Copy link
Contributor Author

@kfricke-hacon kfricke-hacon commented Oct 15, 2014

Hi!

Of course...

Create an empty index.md file or one without meta-data header in your gallery and initiate a 'sigal build' and enjoy the exception:

Traceback (most recent call last):
File "/usr/local/bin/sigal", line 9, in
load_entry_point('sigal==0.8.1', 'console_scripts', 'sigal')()
File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 610, in call
return self.main(_args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 590, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 936, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 782, in invoke
return ctx.invoke(self.callback, *_ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 416, in invoke
return callback(_args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/sigal-0.8.1-py2.7.egg/sigal/init.py", line 132, in build
gal = Gallery(settings, ncpu=ncpu)
File "/usr/local/lib/python2.7/dist-packages/sigal-0.8.1-py2.7.egg/sigal/gallery.py", line 462, in init
album = Album(relpath, settings, dirs, files, self)
File "/usr/local/lib/python2.7/dist-packages/sigal-0.8.1-py2.7.egg/sigal/gallery.py", line 198, in init
self._get_metadata()
File "/usr/local/lib/python2.7/dist-packages/sigal-0.8.1-py2.7.egg/sigal/gallery.py", line 268, in _get_metadata
meta = read_markdown(descfile)
File "/usr/local/lib/python2.7/dist-packages/sigal-0.8.1-py2.7.egg/sigal/utils.py", line 67, in read_markdown
'title': md.Meta.get('title', [''])[0],
AttributeError: 'Markdown' object has no attribute 'Meta'

Some details about our usage scenario: We are using Sigal as our internal intranet event gallery. There we do host tens of thousands of photos of our events. The photos are managed by our marketing department and some other administrative staff.
They can upload the image using SFTP to our server and then initiate the build process of Sigal using some helper scripts on the console.
During this process of uploading images and markdown files it occurs that we have empty markdown files or markdown files without any meta-data.

Your implementation of read_markdown() does rely on existing meta-data in these files. So the result is an exception and cancelled gallery build.
My fix does only read meta-data from the markdown file if present, returning 'None' in case no meta-data or title is given.

@kfricke-hacon
Copy link
Contributor Author

@kfricke-hacon kfricke-hacon commented Oct 15, 2014

I have two lines of additional print() debug in my method. So you should see line 65 in your exception while reproducing this problem.

@saimn
Copy link
Owner

@saimn saimn commented Oct 15, 2014

Thanks for the details. I can reproduce if the file is empty (I didn't test this yesterday), but not if there the file contains a text and no metadata (in this case md.Meta is always set, whereas when the file is empty the meta extension is probably not called).
Returning None is not enough as it will set the title to None. I will check how to handle this correctly.

@saimn saimn merged commit 594ed88 into saimn:master Oct 15, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
saimn added a commit that referenced this pull request Oct 15, 2014
@kfricke-hacon kfricke-hacon deleted the kfricke-hacon:patch-1 branch Jan 9, 2015
@saimn saimn modified the milestone: 0.9 Aug 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.