diff --git a/Project.toml b/Project.toml index 655fb6e..07941a1 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe" +Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [compat] diff --git a/src/Bibliography.jl b/src/Bibliography.jl index 5d08ca5..99dd404 100644 --- a/src/Bibliography.jl +++ b/src/Bibliography.jl @@ -12,6 +12,7 @@ import BibParser: BibTeX, CFF import DataStructures import DataStructures.OrderedSet import FileIO +import Unicode export export_bibtex, import_bibtex export export_cff, import_cff diff --git a/src/staticweb.jl b/src/staticweb.jl index 5334c8c..9b9b1e8 100644 --- a/src/staticweb.jl +++ b/src/staticweb.jl @@ -24,6 +24,18 @@ function xtitle(entry) return isdefined(entry, :title) ? entry.title : get(entry.fields, "title", "") end +function _initial(name) + initial = "" + _name = Unicode.normalize(strip(name)) + if length(_name) > 0 + initial = "$(_name[1])." + for part in split(_name, "-")[2:end] + initial *= "-$(part[1])." + end + end + return initial +end + """ xnames(entry, editors = false; names = :full) @@ -32,12 +44,14 @@ Format the name of an `Entry` for web export. # Arguments: - `entry`: an entry - `editors`: `true` if the name describes editors -- `names`: :full (full names) or :last (last names + first name abbreviation) +- `names`: :full (full names), :last (last names + first name initials), or :lastonly (last names only) +- `and`: `true` if the last two names should be delimited with " and " """ function xnames( entry, editors = false; - names = :full # Current options: :last, :full + names = :full, + and = false ) # forces the names to be editors' name if the entry are Proceedings if !editors && entry.type ∈ ["proceedings"] @@ -45,16 +59,26 @@ function xnames( end entry_names = editors ? entry.editors : entry.authors - if names == :last + if names == :full + parts = map(s -> [s.first, s.middle, s.particle, s.last, s.junior], entry_names) + elseif names == :last + parts = map( + s -> [_initial(s.first), _initial(s.middle), s.particle, s.last, s.junior], + entry_names) + elseif names == :lastonly parts = map(s -> [s.particle, s.last, s.junior], entry_names) else - parts = map(s -> [s.first, s.middle, s.particle, s.last, s.junior], entry_names) + error("Invalid names=$(repr(names)) not in :full, :last, :lastonly") end entry_names = map(parts) do s return join(filter(!isempty, s), " ") end - str = join(entry_names, ", ") + if and + str = join(entry_names, ", ", " and ") + else + str = join(entry_names, ", ") + end return replace(str, r"[\n\r ]+" => " ") # TODO: make it cleaner (is replace still necessary) end diff --git a/test/staticweb.jl b/test/staticweb.jl index b66f6eb..fdfcc82 100644 --- a/test/staticweb.jl +++ b/test/staticweb.jl @@ -2,18 +2,21 @@ using ReferenceTests @testset "staticweb helpers" for file in ["test.bib"] #, "xampl.bib"] #, "ignace_ref.bib"] bib = Bibliography.import_bibtex("../examples/$file") - result = "" - for (key, val) in bib - result *= """ - key: $(key) - title: '$(Bibliography.xtitle(val))' - names: '$(Bibliography.xnames(val))' - in: '$(Bibliography.xin(val))' - year: '$(Bibliography.xyear(val))' - link: '$(Bibliography.xlink(val))' - file: '$(Bibliography.xfile(val))' + for names in [:full, :last, :lastonly] + result = "" + and = (names == :full) + for (key, val) in bib + result *= """ + key: $(key) + title: '$(Bibliography.xtitle(val))' + names: '$(Bibliography.xnames(val; names=names, and=and))' + in: '$(Bibliography.xin(val))' + year: '$(Bibliography.xyear(val))' + link: '$(Bibliography.xlink(val))' + file: '$(Bibliography.xfile(val))' - """ + """ + end + @test_reference "$file-$names.txt" result end - @test_reference "$file.txt" result end diff --git a/test/test.bib-full.txt b/test/test.bib-full.txt new file mode 100644 index 0000000..f83ddd7 --- /dev/null +++ b/test/test.bib-full.txt @@ -0,0 +1,120 @@ +key: CiteEprint +title: 'Automatic Cost Function Learning with Interpretable Compositional Networks' +names: 'Florian Richoux and Jean-François Baffier' + in: 'arXiv:2002.09811 [cs.AI].' +year: '2020' +link: 'https://arxiv.org/abs/2002.09811' +file: 'files/CiteEprint.pdf' + +key: CitekeyArticle +title: 'The independence of the continuum hypothesis' +names: 'P. J. Cohen' + in: 'Proceedings of the National Academy of Sciences, 50(6), 1143--1148, 1963.' +year: '1963' +link: '' +file: 'files/CitekeyArticle.pdf' + +key: CitekeyBook +title: 'Classical mechanics: the theoretical minimum' +names: 'Leonard Susskind and George Hrabovsky' + in: 'Penguin Random House, New York, NY, 2014.' +year: '2014' +link: '' +file: 'files/CitekeyBook.pdf' + +key: CitekeyBooklet +title: 'Canoe tours in {S}weden' +names: 'Maria Swetla' + in: 'Distributed at the Stockholm Tourist Office, 2015.' +year: '2015' +link: '' +file: 'files/CitekeyBooklet.pdf' + +key: CitekeyInbook +title: 'Photosynthesis' +names: 'Lisa A. Urry, Michael L. Cain, Steven A. Wasserman, Peter V. Minorsky and Jane B. Reece' + in: 'Campbell Biology, 187--221, Pearson, New York, NY.' +year: '2016' +link: '' +file: 'files/CitekeyInbook.pdf' + +key: CitekeyIncollection +title: 'Flow Cytometry: The Glass Is Half Full' +names: 'Howard M. Shapiro' + in: 'In Flow Cytometry Protocols, editors, Teresa S. Hawley, Robert G. Hawley, 1--10. Springer, New York, NY, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyIncollection.pdf' + +key: CitekeyInproceedings +title: 'Studying mobile context-aware social services in the wild' +names: 'Paul Holleis, Matthias Wagner and Johan Koolwaaij' + in: ' In Proc. of the 6th Nordic Conf. on Human-Computer Interaction, NordiCHI, 207--216, New York, NY, 2010. ACM.' +year: '2010' +link: '' +file: 'files/CitekeyInproceedings.pdf' + +key: CitekeyManual +title: '{R}: A Language and Environment for Statistical Computing' +names: 'R Core Team' + in: 'R Foundation for Statistical Computing, Vienna, Austria, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyManual.pdf' + +key: CitekeyMastersthesis +title: 'Spin structure of the nucleon in the asymptotic limit' +names: 'Jian Tang' + in: 'Master's thesis, Massachusetts Institute of Technology, Cambridge, MA, 1996.' +year: '1996' +link: '' +file: 'files/CitekeyMastersthesis.pdf' + +key: CitekeyMisc +title: 'Pluto: The 'Other' Red Planet' +names: 'NASA' + in: '\url{https://www.nasa.gov/nh/pluto-the-other-red-planet}, 2015. Accessed: 2018-12-06.' +year: '2015' +link: '' +file: 'files/CitekeyMisc.pdf' + +key: CitekeyPhdthesis +title: 'Relaxation Effects for Coupled Nuclear Spins' +names: 'Robert Charles Rempel' + in: 'PhD thesis, Stanford University, Stanford, CA, 1956.' +year: '1956' +link: '' +file: 'files/CitekeyPhdthesis.pdf' + +key: CitekeyProceedings +title: 'Proceedings of the 17th International Conference on Computation and Natural Computation, Fontainebleau, France' +names: 'Susan Stepney, Sergey Verlan' + in: 'Volume 10867 of Lecture Notes in Computer Science, Cham, Switzerland, 2018. Springer.' +year: '2018' +link: '' +file: 'files/CitekeyProceedings.pdf' + +key: CitekeyTechreport +title: '{W}asatch {S}olar {P}roject Final Report' +names: 'Vicki Bennett, Kate Bowman and Sarah Wright' + in: 'Technical Report DOE-SLC-6903-1, Salt Lake City Corporation, Salt Lake City, UT, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyTechreport.pdf' + +key: CitekeyUnpublished +title: 'Evolution: a revised theory' +names: 'Mohinder Suresh' + in: 'Well, a note, 2006.' +year: '2006' +link: '' +file: 'files/CitekeyUnpublished.pdf' + +key: baffier2017experimental +title: 'Experimental Study of Compressed Stack Algorithms in Limited Memory Environments' +names: 'Jean-François Baffier, Yago Diez and Matias Korman' + in: 'arXiv:1706.04708 [cs.DS].' +year: '2017' +link: 'https://arxiv.org/abs/1706.04708' +file: 'files/baffier2017experimental.pdf' + diff --git a/test/test.bib-last.txt b/test/test.bib-last.txt new file mode 100644 index 0000000..f41ea5b --- /dev/null +++ b/test/test.bib-last.txt @@ -0,0 +1,120 @@ +key: CiteEprint +title: 'Automatic Cost Function Learning with Interpretable Compositional Networks' +names: 'F. Richoux, J.-F. Baffier' + in: 'arXiv:2002.09811 [cs.AI].' +year: '2020' +link: 'https://arxiv.org/abs/2002.09811' +file: 'files/CiteEprint.pdf' + +key: CitekeyArticle +title: 'The independence of the continuum hypothesis' +names: 'P. J. Cohen' + in: 'Proceedings of the National Academy of Sciences, 50(6), 1143--1148, 1963.' +year: '1963' +link: '' +file: 'files/CitekeyArticle.pdf' + +key: CitekeyBook +title: 'Classical mechanics: the theoretical minimum' +names: 'L. Susskind, G. Hrabovsky' + in: 'Penguin Random House, New York, NY, 2014.' +year: '2014' +link: '' +file: 'files/CitekeyBook.pdf' + +key: CitekeyBooklet +title: 'Canoe tours in {S}weden' +names: 'M. Swetla' + in: 'Distributed at the Stockholm Tourist Office, 2015.' +year: '2015' +link: '' +file: 'files/CitekeyBooklet.pdf' + +key: CitekeyInbook +title: 'Photosynthesis' +names: 'L. A. Urry, M. L. Cain, S. A. Wasserman, P. V. Minorsky, J. B. Reece' + in: 'Campbell Biology, 187--221, Pearson, New York, NY.' +year: '2016' +link: '' +file: 'files/CitekeyInbook.pdf' + +key: CitekeyIncollection +title: 'Flow Cytometry: The Glass Is Half Full' +names: 'H. M. Shapiro' + in: 'In Flow Cytometry Protocols, editors, Teresa S. Hawley, Robert G. Hawley, 1--10. Springer, New York, NY, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyIncollection.pdf' + +key: CitekeyInproceedings +title: 'Studying mobile context-aware social services in the wild' +names: 'P. Holleis, M. Wagner, J. Koolwaaij' + in: ' In Proc. of the 6th Nordic Conf. on Human-Computer Interaction, NordiCHI, 207--216, New York, NY, 2010. ACM.' +year: '2010' +link: '' +file: 'files/CitekeyInproceedings.pdf' + +key: CitekeyManual +title: '{R}: A Language and Environment for Statistical Computing' +names: 'R. C. Team' + in: 'R Foundation for Statistical Computing, Vienna, Austria, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyManual.pdf' + +key: CitekeyMastersthesis +title: 'Spin structure of the nucleon in the asymptotic limit' +names: 'J. Tang' + in: 'Master's thesis, Massachusetts Institute of Technology, Cambridge, MA, 1996.' +year: '1996' +link: '' +file: 'files/CitekeyMastersthesis.pdf' + +key: CitekeyMisc +title: 'Pluto: The 'Other' Red Planet' +names: 'NASA' + in: '\url{https://www.nasa.gov/nh/pluto-the-other-red-planet}, 2015. Accessed: 2018-12-06.' +year: '2015' +link: '' +file: 'files/CitekeyMisc.pdf' + +key: CitekeyPhdthesis +title: 'Relaxation Effects for Coupled Nuclear Spins' +names: 'R. C. Rempel' + in: 'PhD thesis, Stanford University, Stanford, CA, 1956.' +year: '1956' +link: '' +file: 'files/CitekeyPhdthesis.pdf' + +key: CitekeyProceedings +title: 'Proceedings of the 17th International Conference on Computation and Natural Computation, Fontainebleau, France' +names: 'Susan Stepney, Sergey Verlan' + in: 'Volume 10867 of Lecture Notes in Computer Science, Cham, Switzerland, 2018. Springer.' +year: '2018' +link: '' +file: 'files/CitekeyProceedings.pdf' + +key: CitekeyTechreport +title: '{W}asatch {S}olar {P}roject Final Report' +names: 'V. Bennett, K. Bowman, S. Wright' + in: 'Technical Report DOE-SLC-6903-1, Salt Lake City Corporation, Salt Lake City, UT, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyTechreport.pdf' + +key: CitekeyUnpublished +title: 'Evolution: a revised theory' +names: 'M. Suresh' + in: 'Well, a note, 2006.' +year: '2006' +link: '' +file: 'files/CitekeyUnpublished.pdf' + +key: baffier2017experimental +title: 'Experimental Study of Compressed Stack Algorithms in Limited Memory Environments' +names: 'J.-F. Baffier, Y. Diez, M. Korman' + in: 'arXiv:1706.04708 [cs.DS].' +year: '2017' +link: 'https://arxiv.org/abs/1706.04708' +file: 'files/baffier2017experimental.pdf' + diff --git a/test/test.bib-lastonly.txt b/test/test.bib-lastonly.txt new file mode 100644 index 0000000..4269187 --- /dev/null +++ b/test/test.bib-lastonly.txt @@ -0,0 +1,120 @@ +key: CiteEprint +title: 'Automatic Cost Function Learning with Interpretable Compositional Networks' +names: 'Richoux, Baffier' + in: 'arXiv:2002.09811 [cs.AI].' +year: '2020' +link: 'https://arxiv.org/abs/2002.09811' +file: 'files/CiteEprint.pdf' + +key: CitekeyArticle +title: 'The independence of the continuum hypothesis' +names: 'Cohen' + in: 'Proceedings of the National Academy of Sciences, 50(6), 1143--1148, 1963.' +year: '1963' +link: '' +file: 'files/CitekeyArticle.pdf' + +key: CitekeyBook +title: 'Classical mechanics: the theoretical minimum' +names: 'Susskind, Hrabovsky' + in: 'Penguin Random House, New York, NY, 2014.' +year: '2014' +link: '' +file: 'files/CitekeyBook.pdf' + +key: CitekeyBooklet +title: 'Canoe tours in {S}weden' +names: 'Swetla' + in: 'Distributed at the Stockholm Tourist Office, 2015.' +year: '2015' +link: '' +file: 'files/CitekeyBooklet.pdf' + +key: CitekeyInbook +title: 'Photosynthesis' +names: 'Urry, Cain, Wasserman, Minorsky, Reece' + in: 'Campbell Biology, 187--221, Pearson, New York, NY.' +year: '2016' +link: '' +file: 'files/CitekeyInbook.pdf' + +key: CitekeyIncollection +title: 'Flow Cytometry: The Glass Is Half Full' +names: 'Shapiro' + in: 'In Flow Cytometry Protocols, editors, Teresa S. Hawley, Robert G. Hawley, 1--10. Springer, New York, NY, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyIncollection.pdf' + +key: CitekeyInproceedings +title: 'Studying mobile context-aware social services in the wild' +names: 'Holleis, Wagner, Koolwaaij' + in: ' In Proc. of the 6th Nordic Conf. on Human-Computer Interaction, NordiCHI, 207--216, New York, NY, 2010. ACM.' +year: '2010' +link: '' +file: 'files/CitekeyInproceedings.pdf' + +key: CitekeyManual +title: '{R}: A Language and Environment for Statistical Computing' +names: 'Team' + in: 'R Foundation for Statistical Computing, Vienna, Austria, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyManual.pdf' + +key: CitekeyMastersthesis +title: 'Spin structure of the nucleon in the asymptotic limit' +names: 'Tang' + in: 'Master's thesis, Massachusetts Institute of Technology, Cambridge, MA, 1996.' +year: '1996' +link: '' +file: 'files/CitekeyMastersthesis.pdf' + +key: CitekeyMisc +title: 'Pluto: The 'Other' Red Planet' +names: 'NASA' + in: '\url{https://www.nasa.gov/nh/pluto-the-other-red-planet}, 2015. Accessed: 2018-12-06.' +year: '2015' +link: '' +file: 'files/CitekeyMisc.pdf' + +key: CitekeyPhdthesis +title: 'Relaxation Effects for Coupled Nuclear Spins' +names: 'Rempel' + in: 'PhD thesis, Stanford University, Stanford, CA, 1956.' +year: '1956' +link: '' +file: 'files/CitekeyPhdthesis.pdf' + +key: CitekeyProceedings +title: 'Proceedings of the 17th International Conference on Computation and Natural Computation, Fontainebleau, France' +names: 'Susan Stepney, Sergey Verlan' + in: 'Volume 10867 of Lecture Notes in Computer Science, Cham, Switzerland, 2018. Springer.' +year: '2018' +link: '' +file: 'files/CitekeyProceedings.pdf' + +key: CitekeyTechreport +title: '{W}asatch {S}olar {P}roject Final Report' +names: 'Bennett, Bowman, Wright' + in: 'Technical Report DOE-SLC-6903-1, Salt Lake City Corporation, Salt Lake City, UT, 2018.' +year: '2018' +link: '' +file: 'files/CitekeyTechreport.pdf' + +key: CitekeyUnpublished +title: 'Evolution: a revised theory' +names: 'Suresh' + in: 'Well, a note, 2006.' +year: '2006' +link: '' +file: 'files/CitekeyUnpublished.pdf' + +key: baffier2017experimental +title: 'Experimental Study of Compressed Stack Algorithms in Limited Memory Environments' +names: 'Baffier, Diez, Korman' + in: 'arXiv:1706.04708 [cs.DS].' +year: '2017' +link: 'https://arxiv.org/abs/1706.04708' +file: 'files/baffier2017experimental.pdf' +