summaryrefslogtreecommitdiff
path: root/html/research/writings.nix
blob: 205bcf68397b71caae2150f49ad4fa9557d5f378 (plain)
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
{
  html,
  data,
  lib,
  ...
}:
let
  attrValsOpt =
    attrs: attrSet: lib.attrVals (builtins.filter (attr: lib.hasAttr attr attrSet) attrs) attrSet;
  concatStringsPrefix =
    prefix: strings: lib.concatStrings (builtins.map (string: prefix + string) strings);
  concatStringsSuffix =
    suffix: strings: lib.concatStrings (builtins.map (string: string + suffix) strings);
  format =
    publication:
    with html;
    with publication;
    {
      inherit
        id
        title
        url
        year
        abstract
        cite
        ;
    }
    // (
      let
        authorsOther = lib.remove "${data.basics.name.first} ${data.basics.name.last}" (
          builtins.map (author: "${author.given} ${author.family}") author
        );
      in
      lib.optionalAttrs (authorsOther != [ ]) {
        authors = "With ${lib.concatStringsSep ", " authorsOther}";
      }
    )
    // lib.optionalAttrs (publication ? note) {
      note = publication.note;
    }
    // lib.optionalAttrs (publication ? container-title) {
      published =
        "In ${em container-title}"
        + concatStringsPrefix ", " (attrValsOpt [ "volume" "issue" "publisher" ] publication);
    }
    // lib.optionalAttrs (publication ? event-title) {
      published = "At ${em event-title}";
    }
    // lib.optionalAttrs (publication ? DOI) {
      doi = "${small "DOI"}: ${href "https://doi.org/${DOI}" (code DOI)}";
    };
  listResearch =
    collection:
    with html;
    section [
      (dl (
        for (sort.reverse.byPath [ "issued" "date-parts" ] collection) (
          publication:
          let
            formatted = format publication;
          in
          with formatted;
          lines [
            (dt { id = "Writings#${id}"; } "${href { target = "_blank"; } url (em title)} (${year})")
            (dd [
              (concatStringsSuffix ". " (attrValsOpt [ "authors" "note" "published" "doi" ] formatted))
              (details [
                (summary "More")
                (dl [
                  (dt "Abstract.")
                  (dd (blockquote abstract))
                  (dt "Cite.")
                  (
                    let
                      citeWith =
                        title: type:
                        details [
                          (summary title)
                          (pre (code (lib.readFile "${data.research.files}/${type}/${id}")))
                        ];
                    in
                    dd [
                      (citeWith "BibLaTeX" "biblatex")
                      (citeWith "BibTeX" "bibtex")
                      (citeWith "CSL JSON" "csljson")
                    ]
                  )
                ])
              ])
            ])
          ]
        )
      ))
    ];
in
{
  conferences = listResearch data.research.conferences;
  journals = listResearch data.research.journals;
  misc = listResearch data.research.misc;
  reports = listResearch data.research.reports;
}