Skip to content

Commit

Permalink
separate different versions for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvlevi committed Aug 7, 2024
1 parent e8217a0 commit 4615d9c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
20 changes: 17 additions & 3 deletions tasks/build_docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ source_header_files = fs.find_files_in_dir(Config.build.source.headers, function
return string.find(str, "%.h");
end);

fs.mkdir(Config.build.dest .. '/' .. 'latest');

-- Parse all headers and generate static pages
local modules = {};
for i, filename in pairs(source_header_files) do
Expand All @@ -27,7 +29,7 @@ for i, filename in pairs(source_header_files) do
modules[module_name] = Parse.header(fs.read_file(Config.build.source.headers .. '/' .. filename));

-- Formatting module page
fs.write_file(Config.build.dest .. '/' .. module_name .. '.html', RootLayout({
fs.write_file(Config.build.dest .. '/' .. 'latest' .. '/' .. module_name .. '.html', RootLayout({
page_name=module_name,
headers=source_header_files,
media=Config.media,
Expand All @@ -40,7 +42,7 @@ end

-- Formatting homepage
local homepage_name = 'Reference';
fs.write_file(Config.build.dest .. '/' .. 'index.html', RootLayout({
fs.write_file(Config.build.dest .. '/' .. 'latest'.. '/' .. 'index.html', RootLayout({
page_name=homepage_name,
headers=source_header_files,
media=Config.media,
Expand All @@ -53,7 +55,7 @@ fs.write_file(Config.build.dest .. '/' .. 'index.html', RootLayout({
-- Copy & Minify source assets
Minify(Config.build.source.js, Minify.js,
Config.build.source.static .. '/' .. 'js',
Config.build.dest .. '/' .. Config.media.assets
Config.build.dest .. '/' .. Config.media.assets
);
Minify(Config.build.source.css, Minify.css,
Config.build.source.static .. '/' .. 'css',
Expand All @@ -69,4 +71,16 @@ for i, filename in pairs(asset_files) do
Config.build.source.static .. '/' .. Config.media.assets .. '/' .. filename
)
);
end

-- Copy latest to its own corresponding version
fs.mkdir(Config.build.dest .. '/v' .. VERSION);
local html_latest_files = fs.find_files_in_dir(Config.build.dest .. '/' .. 'latest' .. '/');
for i, filename in pairs(html_latest_files) do
fs.write_file(
Config.build.dest .. '/v' .. VERSION .. '/' .. filename,
fs.read_file(
Config.build.dest .. '/' .. 'latest' .. '/' .. filename
)
);
end
21 changes: 14 additions & 7 deletions tasks/lib/components/layout/Head.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,40 @@ local luax = require('tasks/lib/luax');
---
function Head(props)
local title = props.page_name .. ' | ' .. props.meta.title;
local thumbnail = props.media.assets ..'/' .. props.media.thumbnail;
local thumbnail = '../' .. props.media.assets ..'/' .. props.media.thumbnail;

return luax('head', {
luax('meta', {charset='UTF-8'}),
luax('meta', {name='viewport', content='width=device-width, initial-scale=1.0'}),
luax('meta', {httpEquiv='X-UA-Compatible', content='ie=edge'}),

-- Basic
luax('meta', {name='description', content=props.meta.description}),
luax('meta', {name='keywords', content=luax.join(props.meta.keywords, ', ')}),
luax('meta', {name='author', content=props.meta.author}),

-- Facebook card
luax('meta', {property='og:title', content=title}),
luax('meta', {property='og:description', content=props.meta.description}),
luax('meta', {property='og:image', content=thumbnail}),
luax('meta', {property='og:url', content=props.meta.url}),

-- Twitter card
luax('meta', {name='twitter:card', content='summary_large_image'}),
luax('meta', {name='twitter:title', content=title}),
luax('meta', {name='twitter:description', content=props.meta.description}),
luax('meta', {name='twitter:image', content=thumbnail}),

-- Only index latest docs
luax('link', {rel='canonical', href=props.meta.url .. '/latest/' }),

luax('link', {rel='stylesheet', href=props.media.assets ..'/style.css'}),
luax('script', {type='text/javascript', src=props.media.assets ..'/index.js'}, {}),

luax('link', {rel='stylesheet', href=props.media.assets .. '/lu5-hljs-theme.css'}),
luax('script', {src= props.media.assets .. '/hljs.min.js'}, {}),

-- CSS
luax('link', {rel='stylesheet', href='../' .. props.media.assets ..'/style.css'}),
luax('link', {rel='stylesheet', href='../' .. props.media.assets .. '/lu5-hljs-theme.css'}),

-- JS
luax('script', {src= '../' .. props.media.assets .. '/hljs.min.js'}, {}),
luax('script', {type='text/javascript', src='../' .. props.media.assets ..'/index.js'}, {}),
luax('script', {
'document.addEventListener("DOMContentLoaded", function (event) {',
'hljs.highlightAll();',
Expand Down
8 changes: 5 additions & 3 deletions tasks/lib/components/layout/RootLayout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ function Layout(props)
luax('main', {
luax('header', {
luax('a', {href="./"}, {
luax('img', {width="100px", src=props.media.assets..'/logo.svg'}),
luax('img', {width="100px", src='../' .. props.media.assets..'/logo.svg'}),
}),
luax('h1', {class="module"}, props.page_name),
luax('button', {class="menuBtn", onclick="toggleMenu()"}, {
luax('img', {
class="menuIcon",
width="40px",
src=props.media.assets..'/arrow_left.svg'
src='../' .. props.media.assets..'/arrow_left.svg'
})
}),
luax('span', {class="text version"}, VERSION)
luax('span', {class="text version"}, {
'v', VERSION
})
}),
props.children
})
Expand Down
10 changes: 9 additions & 1 deletion tasks/lib/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ function write_file(path, content)
local color = '92';
local bytes = #content;
if (bytes > 1024 * 16) then
color = '91'
color = '31'
elseif (bytes > 1024 * 8) then
color = '33'
elseif (bytes > 1024 * 4) then
color = '93'
end

Expand All @@ -39,6 +41,11 @@ function write_file(path, content)
print(fmt_size .. ' written in \x1b[90m' .. path .. '\x1b[0m');
end

function mkdir(path)
-- TODO: Will not work on windows...
os.execute("mkdir -p " .. path)
end

function read_file(path)
local c = io.open(path, 'r');
if (c == nil) then
Expand All @@ -48,6 +55,7 @@ function read_file(path)
end

return {
mkdir=mkdir,
write_file=write_file,
read_file=read_file,
find_files_in_dir=find_files_in_dir
Expand Down
2 changes: 1 addition & 1 deletion tasks/siteconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ return {
keywords = { "Lua", "Creative Coding", "p5.js", "OpenGL", "Lua Interpreter", "programming", "coding", "learn code" },
description = "A Lua interpreter for Creative Coding. "..
"Provides a similar experience to well known p5.js library. "..
"Perfect for running Lua graphical sketches with ease.",
"Perfect learning or quickly running Lua graphical windows.",
},
media={
assets = "assets",
Expand Down

0 comments on commit 4615d9c

Please sign in to comment.