@@ -26,6 +26,10 @@ local function write_file(path, data)
2626 f :close ()
2727end
2828
29+ local function write_lines (path , lines )
30+ write_file (path , table.concat (lines , " \n " ) .. " \n " )
31+ end
32+
2933local function read_lines (path )
3034 local f = assert (io.open (path , " r" ))
3135 local lines = {}
@@ -104,6 +108,25 @@ local function json_encode(value)
104108 end
105109end
106110
111+ local function yaml_quote (value )
112+ return value :gsub (" \\ " , " \\\\ " ):gsub (" \" " , " \\\" " )
113+ end
114+
115+ local function html_escape (value )
116+ return value
117+ :gsub (" &" , " &" )
118+ :gsub (" <" , " <" )
119+ :gsub (" >" , " >" )
120+ end
121+
122+ local function write_front_matter (lines , fields )
123+ lines [# lines + 1 ] = " ---"
124+ for _ , field in ipairs (fields ) do
125+ lines [# lines + 1 ] = string.format (" %s: \" %s\" " , field .key , yaml_quote (field .value ))
126+ end
127+ lines [# lines + 1 ] = " ---"
128+ end
129+
107130local function titleize (name )
108131 local parts = {}
109132 for part in name :gmatch (" [^_%-%s]+" ) do
@@ -178,6 +201,108 @@ local function parse_args(argv)
178201 return opts
179202end
180203
204+ local function write_examples_content (site_dir , examples )
205+ local examples_dir = site_dir .. " /content/examples"
206+ run (" mkdir -p " .. shell_quote (examples_dir ))
207+
208+ local index_lines = {}
209+ write_front_matter (index_lines , {
210+ { key = " title" , value = " Examples" },
211+ { key = " description" , value = " Gallery of Soluna test entries." },
212+ })
213+ index_lines [# index_lines + 1 ] = " "
214+ index_lines [# index_lines + 1 ] = " <section class=\" section\" >"
215+ index_lines [# index_lines + 1 ] = " <div class=\" section-header\" >"
216+ index_lines [# index_lines + 1 ] = " <div>"
217+ index_lines [# index_lines + 1 ] = " <h1 class=\" section-title\" >Examples</h1>"
218+ index_lines [# index_lines + 1 ] = " <p class=\" section-subtitle\" >Gallery of Soluna test entries.</p>"
219+ index_lines [# index_lines + 1 ] = " </div>"
220+ index_lines [# index_lines + 1 ] = " </div>"
221+ index_lines [# index_lines + 1 ] = " </section>"
222+ index_lines [# index_lines + 1 ] = " "
223+ index_lines [# index_lines + 1 ] = " <div class=\" menubar\" ><a href=\" {{< relurl \" /\" >}}\" >home</a></div>"
224+ index_lines [# index_lines + 1 ] = " "
225+ index_lines [# index_lines + 1 ] = " {{< examples_list >}}"
226+ write_lines (examples_dir .. " /_index.md" , index_lines )
227+
228+ for _ , example in ipairs (examples ) do
229+ local lines = {
230+ " ---" ,
231+ string.format (" title: \" %s\" " , yaml_quote (example .title )),
232+ string.format (" example_id: \" %s\" " , yaml_quote (example .id )),
233+ string.format (" entry: \" %s\" " , yaml_quote (example .entry )),
234+ " build:" ,
235+ " list: true" ,
236+ " render: false" ,
237+ " ---" ,
238+ }
239+ write_lines (examples_dir .. " /" .. example .id .. " .md" , lines )
240+ end
241+ end
242+
243+ local function write_docs_content (site_dir , docs )
244+ local docs_dir = site_dir .. " /content/docs"
245+ run (" mkdir -p " .. shell_quote (docs_dir ))
246+
247+ local lines = {}
248+ write_front_matter (lines , {
249+ { key = " title" , value = " Docs" },
250+ { key = " description" , value = " Soluna API reference." },
251+ })
252+ lines [# lines + 1 ] = " "
253+ lines [# lines + 1 ] = " # Docs"
254+ lines [# lines + 1 ] = " "
255+ lines [# lines + 1 ] = " Soluna API reference."
256+ lines [# lines + 1 ] = " "
257+ lines [# lines + 1 ] = " <div class=\" menubar\" >"
258+ lines [# lines + 1 ] = " <a href=\" {{< relurl \" /\" >}}\" >home</a>"
259+ lines [# lines + 1 ] = " ·"
260+ lines [# lines + 1 ] = " <a href=\" #contents\" >contents</a>"
261+ lines [# lines + 1 ] = " ·"
262+ lines [# lines + 1 ] = " <a href=\" #index\" >index</a>"
263+ lines [# lines + 1 ] = " </div>"
264+ lines [# lines + 1 ] = " "
265+ lines [# lines + 1 ] = " <h1 id=\" contents\" ><a name=\" contents\" >Contents</a></h1>"
266+ lines [# lines + 1 ] = " <ul>"
267+ for _ , module in ipairs (docs ) do
268+ lines [# lines + 1 ] = string.format (" <li><a href=\" #%s\" >%s</a></li>" , module .module , html_escape (module .title ))
269+ end
270+ lines [# lines + 1 ] = " </ul>"
271+ lines [# lines + 1 ] = " "
272+ lines [# lines + 1 ] = " <h1 id=\" index\" ><a name=\" index\" >Index</a></h1>"
273+ lines [# lines + 1 ] = " <ul>"
274+ for _ , module in ipairs (docs ) do
275+ for i , block in ipairs (module .blocks ) do
276+ local signature = block .signature or " @block"
277+ lines [# lines + 1 ] = string.format (" <li><a href=\" #%s-%d\" >%s</a></li>" , module .module , i , html_escape (signature ))
278+ end
279+ end
280+ lines [# lines + 1 ] = " </ul>"
281+ lines [# lines + 1 ] = " "
282+ for _ , module in ipairs (docs ) do
283+ lines [# lines + 1 ] = string.format (" <h1 id=\" %s\" ><a name=\" %s\" >%s</a></h1>" , module .module , module .module , html_escape (module .title ))
284+ if module .module ~= " " then
285+ lines [# lines + 1 ] = string.format (" <p><small>%s</small></p>" , html_escape (module .module ))
286+ end
287+ for i , block in ipairs (module .blocks ) do
288+ local signature = block .signature or " @block"
289+ lines [# lines + 1 ] = string.format (" <h3 id=\" %s-%d\" ><code>%s</code></h3>" , module .module , i , html_escape (signature ))
290+ if block .docs and # block .docs > 0 then
291+ lines [# lines + 1 ] = string.format (" <p>%s</p>" , html_escape (table.concat (block .docs , " " )))
292+ end
293+ if block .annos and # block .annos > 0 then
294+ lines [# lines + 1 ] = " <pre>"
295+ for _ , anno in ipairs (block .annos ) do
296+ lines [# lines + 1 ] = " @" .. html_escape (anno )
297+ end
298+ lines [# lines + 1 ] = " </pre>"
299+ end
300+ end
301+ lines [# lines + 1 ] = " "
302+ end
303+ write_lines (docs_dir .. " /_index.md" , lines )
304+ end
305+
181306local opts = parse_args (arg )
182307local soluna_dir = opts .soluna
183308local site_dir = opts .site
@@ -227,6 +352,9 @@ for _, path in ipairs(doc_paths) do
227352 end
228353end
229354
355+ write_examples_content (site_dir , examples )
356+ write_docs_content (site_dir , docs )
357+
230358local examples_payload = json_encode ({
231359 generated_at = os.date (" !%Y-%m-%dT%H:%M:%SZ" ),
232360 examples = examples ,
0 commit comments