mirror of
https://github.com/Ascyii/nvim.git
synced 2026-01-01 04:04:24 -05:00
auto up 23:53:40 up 0:02, 2 users, load average: 0.88, 0.49, 0.20
auto up 00:24:13 up 0:32, 2 users, load average: 0.84, 0.77, 0.74 auto up 17:13:21 up 4:51, 2 users, load average: 1.17, 1.00, 0.87 auto up 18:55:47 up 0:01, 2 users, load average: 0.67, 0.36, 0.14 auto up 18:57:31 up 0:00, 2 users, load average: 0.71, 0.18, 0.06 auto up 19:03:28 up 0:09, 2 users, load average: 0.22, 0.38, 0.26 auto up 01:08:17 up 6:30, 2 users, load average: 0.62, 0.57, 0.51 auto up 02:38:43 up 0:05, 3 users, load average: 0.52, 0.53, 0.25 auto up 10:53:19 up 0:00, 2 users, load average: 1.01, 0.25, 0.08
This commit is contained in:
@@ -116,6 +116,36 @@ function M.get_newest_vl_file(files)
|
||||
return newest_file
|
||||
end
|
||||
|
||||
-- Function to insert chapter reference at top summary section
|
||||
local function add_chapter_to_summary(course, new_vl_name)
|
||||
local book_file = vim.fn.expand(conf.book_file)
|
||||
local rel_path = string.format("%s/VL/%s", course.path:match("university/(.+)$"), new_vl_name)
|
||||
local default_title = new_vl_name
|
||||
local chapter_line = string.format(' - #chapter("%s")[%s]\n', rel_path, default_title:match("^(.-)%."))
|
||||
|
||||
local lines = {}
|
||||
for l in io.lines(book_file) do
|
||||
table.insert(lines, l)
|
||||
end
|
||||
|
||||
local out = io.open(book_file, "w")
|
||||
local inserted = false
|
||||
local right_block = false
|
||||
for _, l in ipairs(lines) do
|
||||
-- insert after the course's existing index line
|
||||
if not inserted and l:match('"' .. course.path:match("university/(.+)$") .. '/index.typ"') then
|
||||
right_block = true
|
||||
end
|
||||
if not inserted and right_block and l:match("^%s*$") then
|
||||
out:write(chapter_line .. "\n" .. l)
|
||||
inserted = true
|
||||
else
|
||||
out:write(l .. "\n")
|
||||
end
|
||||
end
|
||||
out:close()
|
||||
end
|
||||
|
||||
-- Function to create a new VL file based on the template and incrementing the number
|
||||
function M.create_new_vl(course)
|
||||
local vl_dir = course.path .. "/VL"
|
||||
@@ -145,6 +175,8 @@ function M.create_new_vl(course)
|
||||
-- Copy the template if it exists
|
||||
vim.fn.system({ "cp", template_path, new_vl_path })
|
||||
|
||||
add_chapter_to_summary(course, new_vl_name)
|
||||
|
||||
-- Open the new VL file
|
||||
vim.cmd("edit " .. new_vl_path)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user