Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/.quartoignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.Rmd
6 changes: 6 additions & 0 deletions site/_extensions/category-filter/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: Category Filter
author: Nik Richers
version: 1.0.0
contributes:
filters:
- category-filter.lua
59 changes: 59 additions & 0 deletions site/_extensions/category-filter/category-filter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Category Filter Lua Extension
-- Reads listing-filter from YAML frontmatter and injects config as a data attribute

local function meta_to_native(val)
if val == nil then
return nil
end

local mt = getmetatable(val)

-- Check for pandoc List type (used for YAML arrays)
if mt and mt.__name == "List" then
local arr = {}
for i, item in ipairs(val) do
arr[i] = meta_to_native(item)
end
return arr
end

-- Check for pandoc Inlines (YAML string values become Inlines)
if mt and (mt.__name == "Inlines" or mt.__name == "Blocks") then
return pandoc.utils.stringify(val)
end

-- Plain Lua types
local t = type(val)
if t == "string" or t == "number" or t == "boolean" then
return val
elseif t == "table" then
-- Check if it's an array-like table
if #val > 0 and val[1] ~= nil then
local arr = {}
for i, item in ipairs(val) do
arr[i] = meta_to_native(item)
end
return arr
else
-- It's a map/object
local obj = {}
for k, v in pairs(val) do
obj[k] = meta_to_native(v)
end
return obj
end
end

-- Fallback: try stringify
return pandoc.utils.stringify(val)
end

function Meta(meta)
if meta['listing-filter'] then
local config = meta_to_native(meta['listing-filter'])
local json = quarto.json.encode(config)
local escaped = json:gsub("'", "'")
quarto.doc.include_text("after-body",
'<div id="listing-filter-config" style="display:none" data-config=\'' .. escaped .. '\'></div>')
end
end
Loading