Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

cache rendered html; extract titles; all as utf-8 This stashes the HTML version of every entry in memory and uses Mojo::DOM to extract headers from the markup for use as titles. Titles are displayed in $self->{page_navigation}, now available inside templates as ${page_navigation}. In order to keep Mojo::DOM from choking on other input, it uses the open pragma to open everything as UTF-8 by default, which also eliminates a whole class of character encoding bugs and removes some fiddling with Encode::decode() from feed_print(). This is all obviously a more memory-intensive, but caching the markup turns out to have the side effect of making it much faster to render even a large site, probably as much as anything because the HTML in question is only getting generated once per entry instead of (potentially) 2-3 times. This commit isn't very atomic. In the process of roughing it out and testing it, I made a small pile of minor but potentially breaking changes: - Removed entry_map from settings and hardcoded handling of various types of entry as some if-statements instead. - Removed embedded_perl flag in settings - was always turned on in practice, and wasn't very coherent since templating would have broken without it. - bin/wrt-display - now handles the "feed" alias correctly - EntryStore: now supports retrieving values for properties with prop_value() - this isn't currently used, but it seems like a reasonable extension of the property idea. - Added `wrt ls --with-titles`. - Added dependency versions to Build.PL. - Refactored Markup's line_parse() a little. - Refactored some tests to give cleaner / more useful output. - Renamed default template file to "default".
4 years ago
cache rendered html; extract titles; all as utf-8 This stashes the HTML version of every entry in memory and uses Mojo::DOM to extract headers from the markup for use as titles. Titles are displayed in $self->{page_navigation}, now available inside templates as ${page_navigation}. In order to keep Mojo::DOM from choking on other input, it uses the open pragma to open everything as UTF-8 by default, which also eliminates a whole class of character encoding bugs and removes some fiddling with Encode::decode() from feed_print(). This is all obviously a more memory-intensive, but caching the markup turns out to have the side effect of making it much faster to render even a large site, probably as much as anything because the HTML in question is only getting generated once per entry instead of (potentially) 2-3 times. This commit isn't very atomic. In the process of roughing it out and testing it, I made a small pile of minor but potentially breaking changes: - Removed entry_map from settings and hardcoded handling of various types of entry as some if-statements instead. - Removed embedded_perl flag in settings - was always turned on in practice, and wasn't very coherent since templating would have broken without it. - bin/wrt-display - now handles the "feed" alias correctly - EntryStore: now supports retrieving values for properties with prop_value() - this isn't currently used, but it seems like a reasonable extension of the property idea. - Added `wrt ls --with-titles`. - Added dependency versions to Build.PL. - Refactored Markup's line_parse() a little. - Refactored some tests to give cleaner / more useful output. - Renamed default template file to "default".
4 years ago
cache rendered html; extract titles; all as utf-8 This stashes the HTML version of every entry in memory and uses Mojo::DOM to extract headers from the markup for use as titles. Titles are displayed in $self->{page_navigation}, now available inside templates as ${page_navigation}. In order to keep Mojo::DOM from choking on other input, it uses the open pragma to open everything as UTF-8 by default, which also eliminates a whole class of character encoding bugs and removes some fiddling with Encode::decode() from feed_print(). This is all obviously a more memory-intensive, but caching the markup turns out to have the side effect of making it much faster to render even a large site, probably as much as anything because the HTML in question is only getting generated once per entry instead of (potentially) 2-3 times. This commit isn't very atomic. In the process of roughing it out and testing it, I made a small pile of minor but potentially breaking changes: - Removed entry_map from settings and hardcoded handling of various types of entry as some if-statements instead. - Removed embedded_perl flag in settings - was always turned on in practice, and wasn't very coherent since templating would have broken without it. - bin/wrt-display - now handles the "feed" alias correctly - EntryStore: now supports retrieving values for properties with prop_value() - this isn't currently used, but it seems like a reasonable extension of the property idea. - Added `wrt ls --with-titles`. - Added dependency versions to Build.PL. - Refactored Markup's line_parse() a little. - Refactored some tests to give cleaner / more useful output. - Renamed default template file to "default".
4 years ago
  1. #!/bin/sh
  2. # Initialize a stub wrt project.
  3. : <<=cut
  4. =pod
  5. =head1 NAME
  6. wrt-init - initialize a stub wrt repository
  7. =head1 SYNOPSIS
  8. wrt init # Initialize a wrt repository in current directory
  9. wrt init foo # Initialize a wrt repository in directory named foo
  10. wrt init -h # Print help message
  11. =head1 DESCRIPTION
  12. Creates a configuration file, a basic template, and archive and
  13. publication directories in a given path for use with wrt.
  14. If no path is given, the current working directory will be assumed.
  15. Detailed documentation can be found in the L<App::WRT> man page or at
  16. L<https://code.p1k3.com/gitea/brennen/wrt>.
  17. =head1 LICENSE
  18. wrt is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 2 of the License, or
  21. (at your option) any later version.
  22. =head1 AUTHOR
  23. Brennen Bearnes <code@p1k3.com>
  24. =cut
  25. print_help() {
  26. echo "wrt-init - initialize a stub wrt repository"
  27. echo
  28. echo "Usage:"
  29. echo " wrt-init [target directory]"
  30. echo
  31. echo "Creates a configuration file, a basic template, and archive and"
  32. echo "publication directories in a given path for use with wrt."
  33. echo
  34. echo "If no path is given, the current working directory will be assumed."
  35. exit 1
  36. }
  37. if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  38. print_help
  39. fi
  40. init_target="."
  41. if [ "$1" ]; then
  42. init_target="$1"
  43. fi
  44. echo "Initializing new wrt repository in $init_target"
  45. if [ ! -e "$init_target" ]; then
  46. echo "$init_target not found"
  47. exit 66
  48. fi
  49. if [ ! -d "$init_target" ]; then
  50. echo "$init_target is not a directory"
  51. exit 73
  52. fi
  53. if [ -e "$init_target/wrt.json" ]; then
  54. echo "$init_target/wrt.json already exists"
  55. exit 73
  56. fi
  57. printf 'Entries:\t%s/archives/\n' "$init_target"
  58. mkdir -p "$init_target/archives"
  59. printf 'Entries:\t%s/filters/\n' "$init_target"
  60. mkdir -p "$init_target/filters"
  61. printf 'Publish to:\t%s/public/\n' "$init_target"
  62. mkdir -p "$init_target/public"
  63. printf 'Configuration:\t%s/wrt.json\n' "$init_target"
  64. cat > "$init_target/wrt.json" << 'JSON'
  65. {
  66. "entry_dir": "./archives",
  67. "filter_dir": "./filters",
  68. "publish_dir": "./public",
  69. "title_prefix": "your title here",
  70. "template": "default",
  71. "description": "a wrt site",
  72. "url_root": "https://example.com/",
  73. "image_url_root": "https://example.com/",
  74. "favicon_url": "https://example.com/favicon.png",
  75. "template_dir": "./templates",
  76. "stylesheet_url": "https://example.com/css/wrt.css",
  77. "author": "Your Name Here",
  78. "entry_descriptions": {
  79. "new": "newest entries",
  80. "all": "all entries"
  81. }
  82. }
  83. JSON
  84. printf 'Template:\t%s/templates/default\n' "$init_target"
  85. mkdir -p "$init_target/templates"
  86. cat > "$init_target/templates/default" << 'HTML'
  87. <!DOCTYPE html>
  88. <html>
  89. <head>
  90. <title>${title_prefix}::${title}</title>
  91. <meta name="keywords" content="keywords here" />
  92. <meta name="description" content="${description}" />
  93. <meta name="author" content="${author}" />
  94. <link rel="stylesheet" href="${stylesheet_url}" />
  95. <link rel="icon" type="image/x-png" href="${favicon_url}" />
  96. <link rel=alternate type="application/atom+xml" title="${title_prefix} atom feed" href="${url_root}${feed_alias}" />
  97. <link rel=feed type="application/atom+xml" title="${title_prefix} atom feed" href="${url_root}${feed_alias}" />
  98. <link rel="alternate" title="${title_prefix} JSON feed" type="application/json" href="${url_root}${feed_alias}.json" />
  99. </head>
  100. <body>
  101. <perl>
  102. return $self->link_bar();
  103. </perl>
  104. <h1>${title}</h1>
  105. ${content}
  106. ${page_navigation}
  107. <p><small><em>${license}</em></small></p>
  108. </body>
  109. </html>
  110. HTML