@@ -287,12 +287,22 @@ func (w *Wiki) DisplayPageDraft(name string, draftOK bool) any {
287
287
// Pages returns info about all the pages in the wiki.
288
288
func (w * Wiki ) Pages () []wikifier.PageInfo {
289
289
pageNames := w .allPageFiles ()
290
+ return w .pagesIn ("" , pageNames )
291
+ }
292
+
293
+ // PagesInDir returns info about all the pages in the specified directory.
294
+ func (w * Wiki ) PagesInDir (where string ) []wikifier.PageInfo {
295
+ pageNames := w .pageFilesInDir (where )
296
+ return w .pagesIn (where , pageNames )
297
+ }
298
+
299
+ func (w * Wiki ) pagesIn (prefix string , pageNames []string ) []wikifier.PageInfo {
290
300
pages := make ([]wikifier.PageInfo , len (pageNames ))
291
301
292
302
// pages individually
293
303
i := 0
294
304
for _ , name := range pageNames {
295
- pages [i ] = w .PageInfo (name )
305
+ pages [i ] = w .PageInfo (filepath . Join ( prefix , name ) )
296
306
i ++
297
307
}
298
308
@@ -313,11 +323,13 @@ func (pi sortablePageInfo) SortInfo() SortInfo {
313
323
// PagesSorted returns info about all the pages in the wiki, sorted as specified.
314
324
// Accepted sort functions are SortTitle, SortAuthor, SortCreated, and SortModified.
315
325
func (w * Wiki ) PagesSorted (descend bool , sorters ... SortFunc ) []wikifier.PageInfo {
326
+ return _pagesSorted (w .Pages (), descend , sorters ... )
327
+ }
316
328
329
+ func _pagesSorted (pages []wikifier.PageInfo , descend bool , sorters ... SortFunc ) []wikifier.PageInfo {
317
330
// convert to []Sortable
318
- pages := w .Pages ()
319
331
sorted := make ([]Sortable , len (pages ))
320
- for i , pi := range w . Pages () {
332
+ for i , pi := range pages {
321
333
sorted [i ] = sortablePageInfo (pi )
322
334
}
323
335
@@ -336,6 +348,36 @@ func (w *Wiki) PagesSorted(descend bool, sorters ...SortFunc) []wikifier.PageInf
336
348
return pages
337
349
}
338
350
351
+ // PagesAndDirs returns info about all the pages and directories in a directory.
352
+ func (w * Wiki ) PagesAndDirs (where string ) ([]wikifier.PageInfo , []string ) {
353
+ pages := w .PagesInDir (where )
354
+
355
+ // find dirs
356
+ files , _ := os .ReadDir (filepath .Join (w .Opt .Dir .Page , where ))
357
+ dirs := make ([]string , 0 , len (files ))
358
+ for _ , fi := range files {
359
+ if fi .IsDir () {
360
+ dirs = append (dirs , fi .Name ())
361
+ }
362
+ }
363
+
364
+ return pages , dirs
365
+ }
366
+
367
+ // PagesAndDirsSorted returns info about all the pages and directories in a directory, sorted as specified.
368
+ // Accepted sort functions are SortTitle, SortAuthor, SortCreated, and SortModified.
369
+ // Directories are always sorted alphabetically (but still respect the descend flag).
370
+ func (w * Wiki ) PagesAndDirsSorted (where string , descend bool , sorters ... SortFunc ) ([]wikifier.PageInfo , []string ) {
371
+ pages , dirs := w .PagesAndDirs (where )
372
+ pages = _pagesSorted (pages , descend , sorters ... )
373
+ if descend {
374
+ sort .Sort (sort .Reverse (sort .StringSlice (dirs )))
375
+ } else {
376
+ sort .Strings (dirs )
377
+ }
378
+ return pages , dirs
379
+ }
380
+
339
381
// PageMap returns a map of page name to PageInfo for all pages in the wiki.
340
382
func (w * Wiki ) PageMap () map [string ]wikifier.PageInfo {
341
383
pageNames := w .allPageFiles ()
@@ -369,17 +411,15 @@ func (w *Wiki) PageInfo(name string) (info wikifier.PageInfo) {
369
411
info = * pageCat .PageInfo
370
412
}
371
413
372
- // this stuff is available to all
414
+ // add info we can derive from the file
373
415
mod := pgFi .ModTime ()
374
416
info .Path = path
375
417
info .File = filepath .ToSlash (name )
418
+ info .FileNE = filepath .ToSlash (nameNE )
419
+ info .Base = filepath .Base (name )
420
+ info .BaseNE = filepath .Base (nameNE )
376
421
info .Modified = & mod // actual page mod time
377
422
378
- // fallback title to name
379
- if info .Title == "" {
380
- info .Title = nameNE
381
- }
382
-
383
423
// fallback created to modified
384
424
if info .Created == nil {
385
425
info .Created = & mod
0 commit comments