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.

136 lines
3.1 KiB

  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 "Publish to:\t%s/public/\n" "$init_target"
  60. mkdir -p "$init_target/public"
  61. printf "Configuration:\t%s/wrt.json\n" "$init_target"
  62. cat > "$init_target/wrt.json" << 'JSON'
  63. {
  64. "entry_dir": "./archives",
  65. "publish_dir": "./public",
  66. "title_prefix": "your title here",
  67. "template": "default.html",
  68. "description": "a wrt site",
  69. "url_root": "https://example.com/",
  70. "image_url_root": "https://example.com/",
  71. "favicon_url": "https://example.com/favicon.png",
  72. "template_dir": "./templates",
  73. "stylesheet_url": "https://example.com/css/wrt.css",
  74. "author": "Your Name Here",
  75. "entry_descriptions": {
  76. "new": "newest entries",
  77. "all": "all entries"
  78. }
  79. }
  80. JSON
  81. printf "Template:\t%s/templates/default.html\n" "$init_target"
  82. mkdir -p "$init_target/templates"
  83. cat > "$init_target/templates/default.html" << 'HTML'
  84. <!DOCTYPE html>
  85. <html>
  86. <head>
  87. <title>${title_prefix}::${title}</title>
  88. <meta name="keywords" content="keywords here" />
  89. <meta name="description" content="${description}" />
  90. <meta name="author" content="${author}" />
  91. <link rel="stylesheet" href="${stylesheet_url}" />
  92. <link rel="icon" type="image/x-png" href="${favicon_url}" />
  93. </head>
  94. <body>
  95. <perl>
  96. return $self->link_bar();
  97. </perl>
  98. <h1>${title}</h1>
  99. ${content}
  100. <p><small><em>${license}</em></small></p>
  101. </body>
  102. </html>
  103. HTML