Skip to content

Commit

Permalink
publication_list: show the link to the pdf if specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Jan 29, 2016
1 parent 001f4a7 commit bcf7941
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Binary file modified output/__data__/publication-list-screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions tests/data/publication_list/test.bib
Expand Up @@ -4,15 +4,17 @@ @article{a2015
year = 2015, year = 2015,
journal = {Great Journal}, journal = {Great Journal},
volume = 1, volume = 1,
page = {1--10} page = {1--10},
pdf = {/pdf/a2015.pdf}
} }


@book{b2010, @book{b2010,
title = {One Book in 2010}, title = {One Book in 2010},
author = {Nikola Tesla and Isaac Newton}, author = {Nikola Tesla and Isaac Newton},
year = 2010, year = 2010,
isbn = {000-0000000000}, isbn = {000-0000000000},
publisher = {Nikola Tesla Publishing Group} publisher = {Nikola Tesla Publishing Group},
pdf = {http://example.org/b2010.pdf}
} }


@inproceedings{p2015, @inproceedings{p2015,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_publication_list.py
Expand Up @@ -31,10 +31,10 @@ def test_default(self):
expected = ( expected = (
'<div class = "publication-list">' '<div class = "publication-list">'
'<h3>2015</h3><ul>' '<h3>2015</h3><ul>'
'<li class = "publication">.*One article in 2015.*<a href="bibtex/a2015.bib">bibtex</a>.*</li>' '<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 conference in 2015.*<a href="bibtex/p2015.bib">bibtex</a>.*</li>'
'</ul><h3>2010</h3><ul>' '</ul><h3>2010</h3><ul>'
'<li class = "publication">.*One Book in 2010.*<a href="bibtex/b2010.bib">bibtex</a>.*</li>' '<li class = "publication">.*One Book in 2010.*<a href="bibtex/b2010.bib">bibtex</a>.*<a href="http://example.org/b2010.pdf">pdf</a>.*</li>'
'</ul></div>' '</ul></div>'
) )
self.sample = '.. publication_list:: tests/data/publication_list/test.bib' self.sample = '.. publication_list:: tests/data/publication_list/test.bib'
Expand Down
10 changes: 8 additions & 2 deletions v7/publication_list/README.md
Expand Up @@ -23,6 +23,10 @@ The `publication-list` directive accepts multiple options.
publication is generated. If empty, no bibtex file will be created for each publication is generated. If empty, no bibtex file will be created for each
publication. The default is `bibtex`. publication. The default is `bibtex`.


Besides the options available above, if a publication entry has specified a
"pdf" field with a URL to a pdf file, a "pdf" link will be shown below the
publication.

## Example ## Example


A simple example: A simple example:
Expand All @@ -41,15 +45,17 @@ where `my-publication.bib` contains:
year = 2015, year = 2015,
journal = {Great Journal}, journal = {Great Journal},
volume = 1, volume = 1,
page = {1--10} page = {1--10},
pdf = {/pdf/a2015.pdf}
} }


@book{b2010, @book{b2010,
title = {One Book in 2010}, title = {One Book in 2010},
author = {Nikola Tesla and Isaac Newton}, author = {Nikola Tesla and Isaac Newton},
year = 2010, year = 2010,
isbn = {000-0000000000}, isbn = {000-0000000000},
publisher = {Nikola Tesla Publishing Group} publisher = {Nikola Tesla Publishing Group},
pdf = {http://example.org/b2010.pdf}
} }


@inproceedings{p2015, @inproceedings{p2015,
Expand Down
11 changes: 10 additions & 1 deletion v7/publication_list/publication_list.py
Expand Up @@ -89,11 +89,20 @@ def run(self):


html += '<li class = "publication">{}'.format( html += '<li class = "publication">{}'.format(
list(style.format_entries((entry,)))[0].text.render_as('html')) list(style.format_entries((entry,)))[0].text.render_as('html'))

extra_links = ""
if bibtex_dir: # write bib files to bibtex_dir for downloading if bibtex_dir: # write bib files to bibtex_dir for downloading
bib_link = '{}/{}.bib'.format(bibtex_dir, label) bib_link = '{}/{}.bib'.format(bibtex_dir, label)
bib_data = BibliographyData(dict({label: entry})) bib_data = BibliographyData(dict({label: entry}))
bib_data.to_file('/'.join([self.output_folder, bib_link]), 'bibtex') bib_data.to_file('/'.join([self.output_folder, bib_link]), 'bibtex')
html += '<br/>[<a href="{}">bibtex</a>]'.format(bib_link) extra_links += '[<a href="{}">bibtex</a>] '.format(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

html += '</li>' html += '</li>'


if len(data) != 0: # publication list is nonempty if len(data) != 0: # publication list is nonempty
Expand Down

0 comments on commit bcf7941

Please sign in to comment.