From 4615d9cd88ecae8c31279083443179be5fa46d25 Mon Sep 17 00:00:00 2001 From: vlev Date: Tue, 6 Aug 2024 23:55:53 -0400 Subject: [PATCH] separate different versions for docs --- tasks/build_docs.lua | 20 +++++++++++++++++--- tasks/lib/components/layout/Head.lua | 21 ++++++++++++++------- tasks/lib/components/layout/RootLayout.lua | 8 +++++--- tasks/lib/file.lua | 10 +++++++++- tasks/siteconfig.lua | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/tasks/build_docs.lua b/tasks/build_docs.lua index 8b085198..21d583a4 100644 --- a/tasks/build_docs.lua +++ b/tasks/build_docs.lua @@ -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 @@ -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, @@ -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, @@ -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', @@ -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 \ No newline at end of file diff --git a/tasks/lib/components/layout/Head.lua b/tasks/lib/components/layout/Head.lua index 730000bf..11a6e1ec 100644 --- a/tasks/lib/components/layout/Head.lua +++ b/tasks/lib/components/layout/Head.lua @@ -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();', diff --git a/tasks/lib/components/layout/RootLayout.lua b/tasks/lib/components/layout/RootLayout.lua index 11e3a6bf..b2478ebb 100644 --- a/tasks/lib/components/layout/RootLayout.lua +++ b/tasks/lib/components/layout/RootLayout.lua @@ -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 }) diff --git a/tasks/lib/file.lua b/tasks/lib/file.lua index fca44f52..9c9c526d 100644 --- a/tasks/lib/file.lua +++ b/tasks/lib/file.lua @@ -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 @@ -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 @@ -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 diff --git a/tasks/siteconfig.lua b/tasks/siteconfig.lua index 24c7639c..e84b68dd 100644 --- a/tasks/siteconfig.lua +++ b/tasks/siteconfig.lua @@ -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",