...
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn new(args FactoryArgs) !&Site {
|
||||
config: SiteConfig{
|
||||
name: name
|
||||
}
|
||||
root_category: Category{}
|
||||
root: Category{}
|
||||
}
|
||||
sites_global[name] = &site
|
||||
return get(name: name)!
|
||||
|
||||
@@ -9,7 +9,7 @@ pub mut:
|
||||
items []CategoryItem
|
||||
}
|
||||
|
||||
//return the label of the category (last part of the path)
|
||||
// return the label of the category (last part of the path)
|
||||
pub fn (mut c Category) label() !string {
|
||||
if c.path.count('/') == 0 {
|
||||
return c.path
|
||||
@@ -19,61 +19,29 @@ pub fn (mut c Category) label() !string {
|
||||
|
||||
type CategoryItem = Page | Link | Category
|
||||
|
||||
|
||||
|
||||
pub fn (mut self Category) up(path string) !&Category {
|
||||
// Split the requested path into parts
|
||||
path_parts := path.split('/')
|
||||
|
||||
// Start at current category
|
||||
mut current := &self
|
||||
|
||||
// Navigate through each part of the path
|
||||
for part in path_parts {
|
||||
// Skip empty parts (from leading/trailing slashes)
|
||||
if part.len == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if this part already exists in current category's items
|
||||
mut found := false
|
||||
for item in current.items {
|
||||
match item {
|
||||
&Category {
|
||||
item_label := item.label()!
|
||||
if item_label == part {
|
||||
current = item
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
else {}
|
||||
// return all items as CategoryItem references recursive
|
||||
pub fn (mut self Category) items_get() ![]&CategoryItem {
|
||||
mut result := []&CategoryItem{}
|
||||
for i in 0 .. self.items.len {
|
||||
mut c := self.items[i]
|
||||
match mut c {
|
||||
Category {
|
||||
result << c.items_get()!
|
||||
}
|
||||
}
|
||||
|
||||
// If not found, create a new category and add it
|
||||
if !found {
|
||||
mut new_category := Category{
|
||||
path: part
|
||||
collapsible: true
|
||||
collapsed: true
|
||||
items: []CategoryItem{}
|
||||
else {
|
||||
result << &c
|
||||
}
|
||||
current.items << new_category
|
||||
current = &new_category
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fn (mut self Category) page_get(src string)! &Page {
|
||||
for item in self.items {
|
||||
match item {
|
||||
pub fn (mut self Category) page_get(src string) !&Page {
|
||||
for c in self.items_get()! {
|
||||
match c {
|
||||
Page {
|
||||
if item.src == src {
|
||||
return it
|
||||
if c.src == src {
|
||||
return &c
|
||||
}
|
||||
}
|
||||
else {}
|
||||
@@ -82,12 +50,12 @@ fn (mut self Category) page_get(src string)! &Page {
|
||||
return error('Page with src="${src}" not found in site.')
|
||||
}
|
||||
|
||||
fn (mut self Category) link_get(href string)! &Link {
|
||||
for item in self.items {
|
||||
match item {
|
||||
pub fn (mut self Category) link_get(href string) !&Link {
|
||||
for c in self.items_get()! {
|
||||
match c {
|
||||
Link {
|
||||
if item.href == href {
|
||||
return it
|
||||
if c.href == href {
|
||||
return &c
|
||||
}
|
||||
}
|
||||
else {}
|
||||
@@ -96,16 +64,26 @@ fn (mut self Category) link_get(href string)! &Link {
|
||||
return error('Link with href="${href}" not found in site.')
|
||||
}
|
||||
|
||||
fn (mut self Category) category_get(path string)! &Category {
|
||||
for item in self.items {
|
||||
match item {
|
||||
pub fn (mut self Category) category_get(path string) !&Category {
|
||||
for i in 0 .. self.items.len {
|
||||
mut c := self.items[i]
|
||||
match mut c {
|
||||
Category {
|
||||
if item.path == path {
|
||||
return it
|
||||
if c.path == path {
|
||||
return &c
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
return error('Category with path="${path}" not found in site.')
|
||||
}
|
||||
mut new_category := Category{
|
||||
path: path
|
||||
collapsible: true
|
||||
collapsed: true
|
||||
items: []CategoryItem{}
|
||||
}
|
||||
// Add the new category as a sum type variant
|
||||
self.items << new_category
|
||||
// Update current_category_ref to point to the newly added category in the slice
|
||||
return &new_category
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ pub fn (mut self Category) str() string {
|
||||
prefix := if is_last { '└── ' } else { '├── ' }
|
||||
|
||||
match item {
|
||||
NavDoc {
|
||||
Page {
|
||||
result << '${prefix}📄 ${item.label}'
|
||||
result << ' └─ path: ${item.path}'
|
||||
result << ' └─ src: ${item.src}'
|
||||
}
|
||||
NavCat {
|
||||
Category {
|
||||
// Category header
|
||||
collapse_icon := if item.collapsed { '▶ ' } else { '▼ ' }
|
||||
result << '${prefix}${collapse_icon}📁 ${item.label}'
|
||||
result << '${prefix}${collapse_icon}📁 ${item.path}'
|
||||
|
||||
// Category metadata
|
||||
if !item.collapsed {
|
||||
@@ -35,15 +35,15 @@ pub fn (mut self Category) str() string {
|
||||
sub_prefix := if is_last_sub { ' └── ' } else { ' ├── ' }
|
||||
|
||||
match sub_item {
|
||||
NavDoc {
|
||||
result << '${sub_prefix}📄 ${sub_item.label} [${sub_item.src_path}]'
|
||||
Page {
|
||||
result << '${sub_prefix}📄 ${sub_item.label} [${sub_item.src}]'
|
||||
}
|
||||
NavCat {
|
||||
Category {
|
||||
// Nested categories
|
||||
sub_collapse_icon := if sub_item.collapsed { '▶ ' } else { '▼ ' }
|
||||
result << '${sub_prefix}${sub_collapse_icon}📁 ${sub_item.label}'
|
||||
result << '${sub_prefix}${sub_collapse_icon}📁 ${sub_item.path}'
|
||||
}
|
||||
NavLink {
|
||||
Link {
|
||||
result << '${sub_prefix}🔗 ${sub_item.label}'
|
||||
if sub_item.description.len > 0 {
|
||||
result << ' └─ ${sub_item.description}'
|
||||
@@ -53,7 +53,7 @@ pub fn (mut self Category) str() string {
|
||||
}
|
||||
}
|
||||
}
|
||||
NavLink {
|
||||
Link {
|
||||
result << '${prefix}🔗 ${item.label}'
|
||||
result << ' └─ href: ${item.href}'
|
||||
if item.description.len > 0 {
|
||||
|
||||
@@ -3,30 +3,28 @@ module meta
|
||||
@[heap]
|
||||
pub struct Site {
|
||||
pub mut:
|
||||
doctree_path string // path to the export of the doctree site
|
||||
config SiteConfig // Full site configuration
|
||||
root // The root category containing all top-level items
|
||||
doctree_path string // path to the export of the doctree site
|
||||
config SiteConfig // Full site configuration
|
||||
root Category // The root category containing all top-level items
|
||||
announcements []Announcement // there can be more than 1 announcement
|
||||
imports []ImportItem
|
||||
build_dest []BuildDest // Production build destinations (from !!site.build_dest)
|
||||
build_dest_dev []BuildDest // Development build destinations (from !!site.build_dest_dev)
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self Site) page_get(src string)! &Page {
|
||||
pub fn (mut self Site) page_get(src string) !&Page {
|
||||
return self.root.page_get(src)!
|
||||
}
|
||||
|
||||
pub fn (mut self Site) link_get(href string)! &Link {
|
||||
|
||||
pub fn (mut self Site) link_get(href string) !&Link {
|
||||
return self.root.link_get(href)!
|
||||
}
|
||||
|
||||
pub fn (mut self Site) category_get(path string)! &Category {
|
||||
pub fn (mut self Site) category_get(path string) !&Category {
|
||||
return self.root.category_get(path)!
|
||||
}
|
||||
|
||||
//sidebar returns the root category for building the sidebar navigation
|
||||
pub fn (mut self Site) sidebar()! &Category {
|
||||
return self.root
|
||||
// sidebar returns the root category for building the sidebar navigation
|
||||
pub fn (mut self Site) sidebar() !&Category {
|
||||
return &self.root
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,15 @@ import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.web.doctree as doctreetools
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
//=========================================================
|
||||
// PAGES: Process pages and build navigation structure
|
||||
// ============================================================
|
||||
// PAGES & CATEGORIES: Process pages and build navigation structure
|
||||
// ============================================================
|
||||
fn play_pages(mut plbook PlayBook, mut website Site) ! {
|
||||
mut collection_current := ''
|
||||
|
||||
mut category_current := &website.root_category // start at root category, this is basically the navigation tree root
|
||||
mut category_current := &website.root // start at root category, this is basically the navigation tree root
|
||||
|
||||
// ============================================================
|
||||
// PASS 1: Process all page and category actions
|
||||
// PASS 1: Process all page_category and page actions
|
||||
// ============================================================
|
||||
mut all_actions := plbook.find(filter: 'site.')!
|
||||
|
||||
@@ -22,23 +21,31 @@ fn play_pages(mut plbook PlayBook, mut website Site) ! {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip actions that are not page or page_category
|
||||
if action.name != 'page_category' && action.name != 'page' {
|
||||
continue
|
||||
}
|
||||
|
||||
// ========== PAGE CATEGORY ==========
|
||||
if action.name == 'page_category' {
|
||||
mut p := action.params
|
||||
|
||||
// label is empty when not specified (we support label & path for flexibility)
|
||||
mut category_path := p.get_default('path', '')!
|
||||
category_current = category_current.up(category_path)!
|
||||
category_current.collapsible = p.get_default_true('collapsible')
|
||||
category_current.collapsed = p.get_default_true('collapsed')
|
||||
category_path := p.get_default('path', '')!
|
||||
if category_path.len == 0 {
|
||||
return error('!!site.page_category: must specify "path"')
|
||||
}
|
||||
|
||||
// Navigate/create category structure
|
||||
category_current = category_current.category_get(category_path)!
|
||||
category_current.collapsible = p.get_default_true('collapsible')
|
||||
category_current.collapsed = p.get_default_false('collapsed')
|
||||
|
||||
console.print_item('Created page category: "${category_current.path}"')
|
||||
|
||||
console.print_item('Created page category: "${category_current.path}" ')
|
||||
action.done = true
|
||||
println(category_current)
|
||||
|
||||
website.categories << category_current
|
||||
|
||||
$dbg();
|
||||
// $dbg();
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -75,13 +82,15 @@ fn play_pages(mut plbook PlayBook, mut website Site) ! {
|
||||
collection_current = page_collection
|
||||
|
||||
// Get optional page metadata
|
||||
page_label := p.get_default('label', p.get_default('title', '')!)! // is what is shown in the sidebar
|
||||
page_title := p.get_default('title', '')! // is title shown on the page, if not from the page content, if empty then will be brought in from the content
|
||||
mut page_label := p.get_default('label', '')! // CHANGED: added mut
|
||||
if page_label.len == 0 {
|
||||
page_label = p.get_default('title', '')!
|
||||
}
|
||||
|
||||
page_title := p.get_default('title', '')!
|
||||
page_description := p.get_default('description', '')!
|
||||
|
||||
|
||||
|
||||
// Create page
|
||||
// Create page object
|
||||
mut page := Page{
|
||||
src: '${page_collection}:${page_name}'
|
||||
label: page_label
|
||||
@@ -89,14 +98,19 @@ fn play_pages(mut plbook PlayBook, mut website Site) ! {
|
||||
description: page_description
|
||||
draft: p.get_default_false('draft')
|
||||
hide_title: p.get_default_false('hide_title')
|
||||
category_id: category_current
|
||||
hide: p.get_default_false('hide')
|
||||
nav_path: category_current.path
|
||||
}
|
||||
|
||||
website.pages << page
|
||||
// Add page to current category
|
||||
category_current.items << page
|
||||
|
||||
console.print_item('Added page: "${page.src}" (label: "${page.label}")')
|
||||
|
||||
action.done = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
console.print_green('Pages and categories processing complete')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user