default_settings.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Welcome to default_settings.py! You will want to modify these values
  2. # for your own needs and then copy them to settings.py. Copying them
  3. # in the same directory is the mostly likely choice here:
  4. #
  5. # cp default_settings settings.py
  6. # <edit> settings.py
  7. #
  8. # If you prefer to keep the settings elsewhere, just make sure they
  9. # are in your Python path.
  10. import os
  11. import yaml
  12. from pathlib import Path
  13. """
  14. You generally want to start in debug mode to test out the archive,
  15. and then set PROD_ARCHIVE to turn on production settings here. In
  16. production you usually change two things--the site_url and your
  17. html_directory.
  18. """
  19. if os.getenv("PROD_ARCHIVE"):
  20. DEBUG = False
  21. else:
  22. DEBUG = True
  23. """
  24. Set the site url. The default below is good for local testing, but you will
  25. definitely need to set your own value for prod.
  26. """
  27. if DEBUG:
  28. site_url = "http://127.0.0.1:4000"
  29. else:
  30. site_url = os.getenv("SITE_URL")
  31. if not site_url:
  32. raise Exception("You need to configure site_url for prod")
  33. """
  34. Set the zulip icon url. Folks can press the icon to see a
  35. message in the actual Zulip instance.
  36. """
  37. if DEBUG:
  38. zulip_icon_url = "http://127.0.0.1:4000/assets/img/zulip.svg"
  39. else:
  40. # Set this according to how you serve your prod assets.
  41. zulip_icon_url = os.getenv("ZULIP_ICON_URL", None)
  42. """
  43. Set the HTML title of your Zulip archive here.
  44. """
  45. title = "Zulip Chat Archive" # Modify me!
  46. """
  47. Set the path prefix of your URLs for your website.
  48. For example, you might want your main page to have
  49. the path of archive/index.html
  50. """
  51. html_root = os.getenv("HTML_ROOT", "archive") # Modify me!
  52. """
  53. When we get content from your Zulip instance, we first create
  54. JSON files that include all of the content data from the Zulip
  55. instance. Having the data in JSON makes it easy to incrementally
  56. update your data as new messages come in.
  57. You will want to put this in a permanent location outside of
  58. your repo. Here we assume a sibling directory named zulip_json, but
  59. you may prefer another directory structure.
  60. """
  61. json_directory = Path(os.getenv("JSON_DIRECTORY", "../zulip_json"))
  62. """
  63. We write HTML to here.
  64. """
  65. if DEBUG:
  66. html_directory = Path("./archive") # Modify me!
  67. else:
  68. try:
  69. html_directory = Path(os.getenv("HTML_DIRECTORY", None))
  70. except TypeError:
  71. raise Exception(
  72. """
  73. You need to set html_directory for prod, and it
  74. should be a different location than DEBUG mode,
  75. since files will likely have different urls in
  76. anchor tags.
  77. """
  78. )
  79. """
  80. This is where you modify the <head> section of every page.
  81. """
  82. page_head_html = (
  83. '<html>\n<head><meta charset="utf-8"><title>Zulip Chat Archive</title></head>\n'
  84. )
  85. """
  86. This is where you modify the <footer> section of every page.
  87. """
  88. page_footer_html = "\n</html>"
  89. """
  90. You may only want to include certain streams. In `streams.yaml`
  91. file, mention the streams you want to include under `included` section.
  92. Example
  93. ---
  94. included:
  95. - general
  96. - javascript
  97. - data structures
  98. If you want to include all the streams you can use '*'
  99. Example
  100. ---
  101. included:
  102. - '*'
  103. Using '*' includes all the **public streams** in Zulip archive. You
  104. can make the settings more restrictive than that, but not the opposite
  105. direction.
  106. If you want to exclude some public streams, mention them under `excluded`
  107. category in `streams.yaml`
  108. Example:
  109. ---
  110. excluded:
  111. - checkins
  112. - development help
  113. """
  114. try:
  115. with open("streams.yaml") as f:
  116. streams = yaml.load(f, Loader=yaml.BaseLoader)
  117. if "included" not in streams or not streams["included"]:
  118. raise Exception(
  119. "Please specify the streams to be included under `included` section in streams.yaml file"
  120. )
  121. included_streams = streams["included"]
  122. excluded_streams = []
  123. if "excluded" in streams and streams["excluded"]:
  124. excluded_streams = streams["excluded"]
  125. except FileNotFoundError:
  126. raise Exception("Missing streams.yaml file")