-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbib2md.php
executable file
·130 lines (120 loc) · 5.59 KB
/
bib2md.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/* bib2md.php
* Generate Jekyll-compatable .md files from BibTeX file
* - one file per year
* - one file per type of publication
* - single file with full BibTex entries and anchor ids for linking
* - single file with recent publications (since 2020)
* - single file with award publications (look for keyword=award)
* Based on BibtexRef plugin for PmWiki, https://www.pmwiki.org/wiki/Cookbook/BibtexRef
* - modified to generate Markdown - Michele Weigle, July 2021
* Example commands (from bibtexref3-md.php):
$reftag = "jones-websci21";
CompleteBibEntry($bibTexFile, $reftag);
BibSummary($bibTexFile, $reftag);
BibCite($bibTexFile, $reftag);
*/
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'bibtexref3-md.php';
$bibTexFile = 'mweigle.bib';
$outputDir = '../_publications';
$common_preamble = "collection: 'publications'\ndoi-color: '#fcab22'\nacrobat-color: '#f70e0c'\nblogger-color: '#F37100'\n";
// generate one file per year of publications
$years = range("1997", "2021");
foreach ($years as $year) {
if ($year == "1998" || $year == "2002") continue; // MCW: I DIDN'T HAVE PUBS THESE YEARS
$outfile = $year . ".md";
$fp = fopen("$outputDir/$outfile", "w") or die("Unable to open file!");
fwrite($fp, "---\n");
fwrite($fp, "title: \"" . $year . "\"\n");
fwrite($fp, "type: 'year'\n");
fwrite($fp, "permalink: /publications/" . $year . "\n");
fwrite($fp, $common_preamble);
fwrite($fp, "---\n");
// BibQuery(bibtex_filename, filter_condition, sort_condition, max_results)
$paper_string = BibQuery($bibTexFile, "(\$this->get('YEAR') == $year)", "!\$this->get('PUBDATE')", "100");
fwrite($fp, $paper_string);
fclose($fp);
}
// generate one file per type of publication
$types = array("book", "journal", "conference", "techreport", "other");
foreach ($types as $type) {
$outfile = $type . ".md";
$fp = fopen("$outputDir/$outfile", "w") or die("Unable to open file!");
fwrite($fp, "---\n");
switch ($type) {
case "book":
fwrite($fp, "title: \"Books and Book Chapters\"\n");
$paper_string = BibQuery($bibTexFile, "strpos(\$this->entrytype,'BOOK')!==FALSE || strpos(\$this->entrytype,'INCOLLECTION')!==FALSE", "!\$this->get('PUBDATE')", "100");
break;
case "journal":
fwrite($fp, "title: \"Journals and Magazines\"\n");
$paper_string = BibQuery($bibTexFile, "strpos(\$this->entrytype,'ARTICLE')!==FALSE", "!\$this->get('PUBDATE')", "100");
break;
case "conference":
fwrite($fp, "title: \"Conferences and Workshops (Peer-Reviewed)\"\n");
$paper_string = BibQuery($bibTexFile, "strpos(\$this->entrytype,'INPROCEEDINGS')!==FALSE", "!\$this->get('PUBDATE')", "100");
break;
case "techreport":
fwrite($fp, "title: \"Tech Reports\"\n");
$paper_string = BibQuery($bibTexFile, "strpos(\$this->entrytype,'TECHREPORT')!==FALSE", "!\$this->get('PUBDATE')", "100");
break;
case "other":
fwrite($fp, "title: \"Other (Poster Presentations, Dissertation, Misc)\"\n");
$paper_string = BibQuery($bibTexFile, "strpos(\$this->entrytype,'MISC')!==FALSE || strpos(\$this->entrytype,'PHDTHESIS')!==FALSE", "!\$this->get('PUBDATE')", "100");
break;
}
fwrite($fp, "type: 'type'\n");
fwrite($fp, "permalink: /publications/" . $type . "\n");
fwrite($fp, $common_preamble);
fwrite($fp, "---\n");
fwrite($fp, $paper_string);
fclose($fp);
}
// generate single file with full BibTeX entry for all
$outfile = "bibtex.md";
$fp = fopen("$outputDir/$outfile", "w") or die("Unable to open file!");
fwrite($fp, "---\n");
fwrite($fp, "title: BibTeX\n");
fwrite($fp, "type: 'bibtex'\n");
fwrite($fp, "permalink: /publications/bibtex\n");
fwrite($fp, $common_preamble);
fwrite($fp, "---\n");
$bibentries = ParseBibFile($bibTexFile);
foreach ($bibentries as $entry) {
foreach ($entry as $bib) {
// get ref for each $bib
$ref = $bib->entryname;
$paper_string = CompleteBibEntry($bibTexFile, $ref);
fwrite($fp, $paper_string);
}
}
fclose($fp);
// generate single file with recent publications (since $year)
$outfile = "recent.md";
$year = "2020";
$fp = fopen("$outputDir/$outfile", "w") or die("Unable to open file!");
fwrite($fp, "---\n");
fwrite($fp, "title: \"Recent Publications and Talks\"\n");
fwrite($fp, "type: 'recent'\n");
fwrite($fp, "permalink: /publications/recent\n");
fwrite($fp, $common_preamble);
fwrite($fp, "---\n");
// set a max of 10 recent papers
$paper_string = BibQuery($bibTexFile, "(\$this->get('YEAR') >= \"$year\")", "!\$this->get('PUBDATE')", "10");
fwrite($fp, $paper_string);
fclose($fp);
// generate single file with award publications
$outfile = "award.md";
$fp = fopen("$outputDir/$outfile", "w") or die("Unable to open file!");
fwrite($fp, "---\n");
fwrite($fp, "title: \"Award Publications\"\n");
fwrite($fp, "type: 'award'\n");
fwrite($fp, "permalink: /publications/award\n");
fwrite($fp, $common_preamble);
fwrite($fp, "---\n");
$paper_string = BibQuery($bibTexFile, "(\$this->get('KEYWORD') == 'award')", "!\$this->get('PUBDATE')", "100");
fwrite($fp, $paper_string);
fclose($fp);
?>