Skip to content

Commit

Permalink
publication_list: create a "abstract and details" page for each paper
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Feb 7, 2016
1 parent 852332a commit 09d4f8c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
6 changes: 3 additions & 3 deletions tests/test_publication_list.py
Expand Up @@ -31,10 +31,10 @@ def test_default(self):
expected = (
'<div class = "publication-list">'
'<h3>2015</h3><ul>'
'<li class = "publication">.*One article in 2015.*<a href="bibtex/a2015.bib">BibTeX</a>.*<a href="/pdf/a2015.pdf">PDF</a>.*</li>'
'<li class = "publication">.*One conference in 2015.*<a href="bibtex/p2015.bib">BibTeX</a>.*</li>'
'<li class = "publication">.*One article in 2015.*<a href="https://example.com/bibtex/a2015.bib">BibTeX</a>.*<a href="/pdf/a2015.pdf">PDF</a>.*<a href="https://example.com/papers/a2015.html">abstract and details</a>.*</li>'
'<li class = "publication">.*One conference in 2015.*<a href="https://example.com/bibtex/p2015.bib">BibTeX</a>.*<a href="https://example.com/papers/p2015.html">abstract and details</a>.*</li>'
'</ul><h3>2010</h3><ul>'
'<li class = "publication">.*One Book in 2010.*<a href="bibtex/b2010.bib">BibTeX</a>.*<a href="http://example.org/b2010.pdf">PDF</a>.*</li>'
'<li class = "publication">.*One Book in 2010.*<a href="https://example.com/bibtex/b2010.bib">BibTeX</a>.*<a href="http://example.org/b2010.pdf">PDF</a>.*<a href="https://example.com/papers/b2010.html">abstract and details</a>.*</li>'
'</ul></div>'
)
self.sample = '.. publication_list:: tests/data/publication_list/test.bib\n\t:highlight_author: Nikola Tesla'
Expand Down
4 changes: 4 additions & 0 deletions v7/publication_list/README.md
Expand Up @@ -19,6 +19,10 @@ The `publication-list` directive accepts multiple options.
publication is generated. If empty, no bibtex file will be created for each
publication. The default is `bibtex`.

* `:detail_page_dir:` indicates the directory where the details pages of the
publications are stored. If empty, no details page will be created. The
default is `papers`.

* `:highlight_author:` indicates the author to highlight. Usually this is the
owner of the website.

Expand Down
39 changes: 35 additions & 4 deletions v7/publication_list/publication_list.py
Expand Up @@ -43,6 +43,7 @@ class Plugin(RestExtension):
def set_site(self, site):
self.site = site
directives.register_directive('publication_list', PublicationList)
PublicationList.site = self.site
PublicationList.output_folder = self.site.config['OUTPUT_FOLDER']
return super(Plugin, self).set_site(site)

Expand All @@ -55,6 +56,7 @@ class PublicationList(Directive):
required_arguments = 1
option_spec = {
'bibtex_dir': directives.unchanged,
'detail_page_dir': directives.unchanged,
'highlight_author': directives.unchanged,
'style': directives.unchanged
}
Expand All @@ -63,6 +65,7 @@ def run(self):

style = find_plugin('pybtex.style.formatting', self.options.get('style', 'unsrt'))()
bibtex_dir = self.options.get('bibtex_dir', 'bibtex')
detail_page_dir = self.options.get('detail_page_dir', 'papers')
highlight_author = self.options.get('highlight_author', None)
self.state.document.settings.record_dependencies.add(self.arguments[0])

Expand All @@ -82,6 +85,12 @@ def run(self):
except OSError: # probably because the dir already exists
pass

if detail_page_dir: # create the detail page dir if the option is set
try:
os.mkdir(os.path.sep.join((self.output_folder, detail_page_dir)))
except OSError: # probably because the dir already exists
pass

for label, entry in data:
# print a year title when year changes
if entry.fields['year'] != cur_year:
Expand All @@ -97,17 +106,39 @@ def run(self):
html += '<li class = "publication">' + pub_html

extra_links = ""
bib_data = BibliographyData(dict({label: entry})) # detail_page_dir may need it later
if bibtex_dir: # write bib files to bibtex_dir for downloading
bib_link = '{}/{}.bib'.format(bibtex_dir, label)
bib_data = BibliographyData(dict({label: entry}))
bib_data.to_file('/'.join([self.output_folder, bib_link]), 'bibtex')
extra_links += '[<a href="{}">BibTeX</a>] '.format(bib_link)
extra_links += '[<a href="{}">BibTeX</a>] '.format(
self.site.config['BASE_URL'] + bib_link)

if 'pdf' in entry.fields: # the link to the pdf file
extra_links += '[<a href="{}">PDF</a>] '.format(entry.fields['pdf'])

if extra_links:
html += '<br/>' + extra_links
if extra_links or detail_page_dir:
html += '<br/>'
html += extra_links

if detail_page_dir: # render the details page of a paper
page_url = '/'.join((detail_page_dir, label + '.html'))
html += ' [<a href="{}">abstract and details</a>]'.format(
self.site.config['BASE_URL'] + page_url)
context = {
'title': entry.fields['title'],
'abstract': entry.fields['abstract'] if 'abstract' in entry.fields else '',
'bibtex': bib_data.to_string('bibtex'),
'default_lang': self.site.config['DEFAULT_LANG'],
'lang': self.site.config['DEFAULT_LANG'],
'permalink': self.site.config['SITE_URL'] + page_url,
'reference': pub_html,
'extra_links': extra_links
}
self.site.render_template(
'publication.tmpl',
os.path.sep.join((self.output_folder, detail_page_dir, label + '.html')),
context,
)

html += '</li>'

Expand Down

0 comments on commit 09d4f8c

Please sign in to comment.