htm.xgo 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. html := import("html").Renderer()
  2. paths := import("paths")
  3. log := import("log")
  4. text := import("text")
  5. os := import("os")
  6. print_header := func(c) {
  7. header := html.nav({
  8. id: "main-nav"
  9. })
  10. nav_file_links := []
  11. if c.is_index {
  12. nav_file_links += []
  13. if c.http.request.url.path != "/" {
  14. nav_file_links += [
  15. html.a({
  16. href: ".."
  17. }).body(
  18. "<<<"
  19. )
  20. ]
  21. }
  22. dir := os.open(paths.dir(c.pp.fpath))
  23. names := dir.readdirnames(0)
  24. for _, name in names {
  25. if text.has_suffix(name, c.pp_ext) {
  26. name = name[:len(name)-len(c.pp_ext)]
  27. }
  28. if name == c.index_suffix {
  29. continue
  30. }
  31. ext := paths.ext(name)
  32. href := "./" + name
  33. if !ext {
  34. href += "/"
  35. }
  36. nav_file_links += [html.a({
  37. href: href
  38. }).body(
  39. name
  40. )]
  41. }
  42. } else {
  43. nav_file_links += [html.a({
  44. href: "."
  45. }).body(
  46. "<<<"
  47. )]
  48. }
  49. header.body(
  50. html.div({
  51. class: "files"
  52. }).body(
  53. nav_file_links...
  54. )
  55. )
  56. header.add(html.button({
  57. id: "create-heading-nav-btn"
  58. }).body(
  59. "Содержание"
  60. ))
  61. c.pp.print(html.button({
  62. id: "top-btn"
  63. }).body(
  64. "TOP"
  65. ))
  66. c.pp.print(header)
  67. }
  68. export {
  69. print_header : print_header
  70. }