gnunetbib

Bibliography (BibTeX, based on AnonBib)
Log | Files | Refs | README | LICENSE

commit b2160e7ccd3f6a4a8988132742cd76cb133d62d3
parent 3bebdf43b809427d43e42804358177ff2633257a
Author: Nils Gillmann <ng0@n0.is>
Date:   Tue,  9 Oct 2018 11:53:42 +0000

Add ability to download single .bib files

Signed-off-by: Nils Gillmann <ng0@n0.is>

Diffstat:
M.gitignore | 1+
MBibTeX.py | 24+++++++++++++++++++++---
MMakefile | 11+++++++++++
Manonbib.cfg | 2++
Mconfig.py | 2+-
MwriteHTML.py | 14+++++++++++++-
6 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -13,6 +13,7 @@ /cite_cache /full /bibtex.json +/bib/ # emacs: \#*\# diff --git a/BibTeX.py b/BibTeX.py @@ -553,11 +553,18 @@ class BibTeXEntry: if self.get('month') or self.get('year'): res.append(", %s %s" % (self.get('month', ''), self.get('year', ''))) + # FIXME: less clauses. elif self.type == 'mastersthesis' or self.type == 'phdthesis': if self.get('type'): + if self.type == 'mastersthesis' or\ + self.type == 'Master' or\ + self.type == 'Masters' or\ + self.type == 'Master\'s': + res = ["Master thesis"] + if self.type == 'Bachelor' or\ + self.type == 'Bachelors': + res = ["Bachelor thesis"] res = [self['type']] - elif self.type == 'mastersthesis': - res = ["Masters's thesis"] else: res = ["Ph.D. thesis"] if self.get('school'): @@ -601,9 +608,20 @@ class BibTeXEntry: res.append((" <span class='availability'>" "(<a href='%s'>BibTeX&nbsp;entry</a>)" "</span>") %bibtexurl) + + # Produce the link to the dot bib file 'record.bib' for the + # current record, assuming it is relative from FILE in + # directory "../bib/". + # FIXME: move everything into 'out', allowing to build + # a website with relative links and more structure. + bibtexurl_file = "../bib/%s" %url_untranslate(self.key) + res.append((" <span class='availability'>" + "(<a href='%s/record.bib'>Download&nbsp;bibtex&nbsp;record</a>)" + "</span>") + %bibtexurl_file) return htmlize("".join(res)) - def to_html(self, cache_path="./cache", base_url="."): + def to_html(self, cache_path="./cache", base_url="html"): """ Return the HTML for this entry. """ diff --git a/Makefile b/Makefile @@ -2,7 +2,18 @@ PYTHON=python2 VERSION=0.3-dev all: + @rm -rf html/ $(PYTHON) writeHTML.py anonbib.cfg + # @mkdir -p `pwd`/html + # @mv `pwd`/full `pwd`/html/ + # @mv `pwd`/bib `pwd`/html/ + # @mv `pwd`/date.html `pwd`/html/ + # @ln -s `pwd`/html/date.html `pwd`/html/index.html + # @mv `pwd`/topic.html `pwd`/html/ + # @mv `pwd`/author.html `pwd`/html/ + # @mv `pwd`/bibtex.html `pwd`/html/ + # @cp -r `pwd`/css `pwd`/html/css + # @cp -r `pwd`/cache `pwd`/html/cache clean: rm -f *~ */*~ *.pyc *.pyo diff --git a/anonbib.cfg b/anonbib.cfg @@ -13,6 +13,8 @@ CACHE_DIR = "cache" # Where do we cache citations papers (relative to OUTPUT_DIR) CITE_CACHE_DIR = "cite_cache" +BIB_DIRECTORY = "bib" + # Are there subsections for cached papers? This is useful for putting # different Apache permission on different directories. CACHE_SECTIONS = [] diff --git a/config.py b/config.py @@ -11,7 +11,7 @@ _KEYS = ["ALL_TAGS", "MASTER_BIB", "NO_COLLAPSE_AUTHORS", "OMIT_ENTRIES", "OUTPUT_DIR", "TEMPLATE_FILE", "BIBTEX_TEMPLATE_FILE", "REQUIRE_KEY", "TAG_TITLES", "TAG_DIRECTORIES", "TAG_SHORT_TITLES", - "MULTI_VAL_FIELDS"] + "MULTI_VAL_FIELDS", "BIB_DIRECTORY"] for _k in _KEYS: globals()[_k] = None diff --git a/writeHTML.py b/writeHTML.py @@ -125,7 +125,6 @@ def jsonDumper(obj): e['key'] = obj.key return e else: - #raise TypeError("Do not know how to serialize %s"%(obj.__class,)) raise_with_traceback(TypeError("Do not know how to serialize %s"%(obj.__class,))) def writePageSet(config, bib, tag): @@ -245,6 +244,19 @@ def writePageSet(config, bib, tag): json.dump(entries, bibtex_json_file, default=jsonDumper) bibtex_json_file.close() + # Produce NAME with EXTENSION 'bib' as a FILE holding one + # bib record. + bibdir = config.BIB_DIRECTORY + biboutdir = os.path.join(config.OUTPUT_DIR, bibdir) + for ent in entries: + bib_file_dir = os.path.join(biboutdir, ent.key) + if not os.path.exists(bib_file_dir): + os.makedirs(bib_file_dir, 0755) + single_bib_file = open(os.path.join(bib_file_dir, + "record.bib"), + 'w') + print("%s" % ent.format(90, 8, 1), file=single_bib_file) + single_bib_file.close() if __name__ == '__main__': if len(sys.argv) == 2: