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.

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