Sources of the site gergely.polonkai.eu, Jekyll version
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.
 
 
 
 
 
 

111 lines
3.2 KiB

  1. # -*- coding: utf-8 -*-
  2. import os
  3. import shutil
  4. import sys
  5. import datetime
  6. from invoke import task
  7. from invoke.util import cd
  8. from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
  9. from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
  10. SETTINGS_FILE_BASE = 'pelicanconf.py'
  11. SETTINGS = {}
  12. SETTINGS.update(DEFAULT_CONFIG)
  13. LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
  14. SETTINGS.update(LOCAL_SETTINGS)
  15. CONFIG = {
  16. 'settings_base': SETTINGS_FILE_BASE,
  17. 'settings_publish': 'publishconf.py',
  18. # Output path. Can be absolute or relative to tasks.py. Default: 'output'
  19. 'deploy_path': SETTINGS['OUTPUT_PATH'],
  20. # Port for `serve`
  21. 'port': 8000,
  22. }
  23. @task
  24. def clean(c):
  25. """Remove generated files"""
  26. if os.path.isdir(CONFIG['deploy_path']):
  27. shutil.rmtree(CONFIG['deploy_path'])
  28. os.makedirs(CONFIG['deploy_path'])
  29. @task
  30. def build(c):
  31. """Build local version of site"""
  32. c.run('pelican -s {settings_base}'.format(**CONFIG))
  33. @task
  34. def rebuild(c):
  35. """`build` with the delete switch"""
  36. c.run('pelican -d -s {settings_base}'.format(**CONFIG))
  37. @task
  38. def regenerate(c):
  39. """Automatically regenerate site upon file modification"""
  40. c.run('pelican -r -s {settings_base}'.format(**CONFIG))
  41. @task
  42. def serve(c):
  43. """Serve site at http://localhost:$PORT/ (default port is 8000)"""
  44. class AddressReuseTCPServer(RootedHTTPServer):
  45. allow_reuse_address = True
  46. server = AddressReuseTCPServer(
  47. CONFIG['deploy_path'],
  48. ('', CONFIG['port']),
  49. ComplexHTTPRequestHandler)
  50. sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG))
  51. server.serve_forever()
  52. @task
  53. def reserve(c):
  54. """`build`, then `serve`"""
  55. build(c)
  56. serve(c)
  57. @task
  58. def preview(c):
  59. """Build production version of site"""
  60. c.run('pelican -s {settings_publish}'.format(**CONFIG))
  61. @task
  62. def livereload(c):
  63. """Automatically reload browser tab upon file modification."""
  64. from livereload import Server
  65. build(c)
  66. server = Server()
  67. # Watch the base settings file
  68. server.watch(CONFIG['settings_base'], lambda: build(c))
  69. # Watch content source files
  70. content_file_extensions = ['.md', '.rst']
  71. for extension in content_file_extensions:
  72. content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
  73. server.watch(content_blob, lambda: build(c))
  74. # Watch the theme's templates and static assets
  75. theme_path = SETTINGS['THEME']
  76. server.watch('{}/templates/*.html'.format(theme_path), lambda: build(c))
  77. static_file_extensions = ['.css', '.js']
  78. for extension in static_file_extensions:
  79. static_file = '{0}/static/**/*{1}'.format(theme_path, extension)
  80. server.watch(static_file, lambda: build(c))
  81. # Serve output path on configured port
  82. server.serve(port=CONFIG['port'], root=CONFIG['deploy_path'])
  83. @task
  84. def publish(c):
  85. """Publish to production via rsync"""
  86. c.run('pelican -s {settings_publish}'.format(**CONFIG))
  87. c.run(
  88. 'rsync --delete --exclude ".DS_Store" -pthrvz -c '
  89. '-e "ssh -p {ssh_port}" '
  90. '{} {ssh_user}@{ssh_host}:{ssh_path}'.format(
  91. CONFIG['deploy_path'].rstrip('/') + '/',
  92. **CONFIG))