Skip to content

Commit

Permalink
Handle files + more robust filter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoWinterhalter committed Oct 25, 2024
1 parent 9a828e6 commit 55200a5
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
67 changes: 64 additions & 3 deletions pandoc/paper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,71 @@ function CodeBlock(el)
error("Failed to decode JSON:\n" .. el.text)
end

local title = data.title or ""
local url = data.url
local authors = data.authors or ""
local venue = data.venue
local year = data.year
local files = data.files or pandoc.List()

local header = {}

if url then
header = { pandoc.Link(title, url) }
else
header = { pandoc.Str(title) }
end

local sub = {}

if venue and year then
sub = { pandoc.Str(string.format("%s (%s)", venue, year)) }
elseif venue then
sub = { pandoc.Str(venue) }
elseif year then
sub = { pandoc.Str(year) }
end

local file_info = files:map(function(data)
local s = data.text or ""
local type = data.type
local src = data.src or ""

local icon = ""

if type == "pdf" then
icon = "<i class=\"fa-solid fa-file-pdf\"></i>"
elseif type == "bib" then
icon = "<i class=\"fa-solid fa-quote-left\"></i>"
elseif type == "code" then
icon = "<i class=\"fa-solid fa-file-code\"></i>"
elseif type == "video" then
icon = "<i class=\"fa-solid fa-file-video\"></i>"
elseif type == "txt" then
icon = "<i class=\"fa-solid fa-file-lines\"></i>"
elseif type == "img" then
icon = "<i class=\"fa-solid fa-file-image\"></i>"
elseif type == "zip" then
icon = "<i class=\"fa-solid fa-file-zipper\"></i>"
elseif type == "slides" then
icon = "<i class=\"fa-solid fa-file-powerpoint\"></i>"
else
icon = "<i class=\"fa-solid fa-file\"></i>"
end

local html_output = string.format(
"<a href=\"%s\">%s %s</a>",
src, icon, s
)

return pandoc.RawBlock("html", html_output)
end)

local div_content = {
pandoc.Header(3, {pandoc.Link(data.title, data.url)}),
pandoc.Para({pandoc.Str(data.authors)}, {class = "authors"}),
pandoc.Para({pandoc.Str(data.venue .. " (" .. data.year .. ")")}, {class = "venue"}) -- It seems the class cannot be set
pandoc.Header(3, header),
pandoc.Para({pandoc.Str(authors)}, {class = "authors"}),
pandoc.Para(sub, {class = "venue"}), -- It seems the class cannot be set
pandoc.Div(file_info, { class = "files" })
}

local div = pandoc.Div(div_content, {class = "paper"})
Expand Down
22 changes: 18 additions & 4 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ My workflow is usually to use <kbd>Ctrl</kbd> + <kbd>C</kbd> /
"authors": "Templato Urnehm, U. N. Owen",
"venue": "Principles of Awesomeness (PAW)",
"year": "2023",
"url": "https://basicpage.github.io"
"url": "https://basicpage.github.io",
"files": [
{ "text": "Paper", "type": "pdf", "src": "foo.pdf" },
{ "text": "Bibtex", "type": "bib", "src": "foo.bib" },
{ "text": "Formalisation", "type": "code", "src": "foo.v" }
]
```

## Journal papers
Expand All @@ -56,13 +61,22 @@ My workflow is usually to use <kbd>Ctrl</kbd> + <kbd>C</kbd> /
"title": "How to tame your wagon",
"authors": "Templato Urnehm",
"venue": "Journal of Automatic Rejection (JAR)",
"year": "2022",
"url": "https://basicpage.github.io"
"year": "2022"
```

## Drafts

None ☠️
```paper
"title": "TBD",
"authors": "TBD",
"files": [
{ "text": "🐱 video", "type": "video", "src": "foo.mov" },
{ "text": "Poem", "type": "txt", "src": "foo.txt" },
{ "text": "My picture", "type": "img", "src": "img/profile.png" },
{ "text": "💣", "type": "zip", "src": "foo.zip" },
{ "text": "Slides", "type": "slides", "src": "foo.key" }
]
```

# Education

Expand Down
23 changes: 23 additions & 0 deletions website/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,26 @@ section.paper p {
color: rgb(136, 136, 136);
margin: 0;
}

div.files {
display: flex;
justify-content: flex-start;
flex-direction: row;
flex-wrap: wrap;
align-items: baseline;
gap: 5px 0;
}

div.files a {
border-radius: 5px;
padding: 4px;
margin-right: 5px;
background: #e5e7e8;
color: #343d44;
font-size: small;
}

div.files a:hover {
background: #91c3ea;
text-decoration: none;
}

0 comments on commit 55200a5

Please sign in to comment.