Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option on whether to enable Jekyll output. #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ archive.
stream_blacklist=hidden, other hidden
# The title of the archive
title=Lean Prover Zulip Chat Archive
# (optional) Whether to emit output in Jekyll format
jekyll_output=true
```
* Optionally, modify the display generation code to fit your needs. The
defaults are based on the [leanprover-community Jekyll
Expand Down
21 changes: 15 additions & 6 deletions archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
md_index = None
last_updated_dir = None
last_updated_file = None
jekyll_output = True

def read_config():
global client
Expand All @@ -58,8 +59,9 @@ def read_config():
global md_index
global last_updated_dir
global last_updated_file
global jekyll_output

def get_config(section: str, key: str, default_value: Optional[str]=None) -> Optional[str]:
def get_config(section: str, key: str, default_value: Optional[str] = None) -> Optional[str]:
if config_file.has_option(section, key):
return config_file.get(section, key)
return default_value
Expand Down Expand Up @@ -107,6 +109,9 @@ def get_config(section: str, key: str, default_value: Optional[str]=None) -> Opt
last_updated_dir = Path("_includes") # directory to store update timestamp
last_updated_file = Path("archive_update.html") # filename for update timestamp

# Whether to emit output in Jekyll format
if config_file.has_option('archive', 'jekyll_output'):
jekyll_output = config_file.getboolean('archive', 'jekyll_output')

## Customizable display functions.

Expand Down Expand Up @@ -141,7 +146,8 @@ def write_stream_index(streams):
sanitize_stream(s, streams[s]['id']),
num_topics,
'' if num_topics == 1 else 's'))
outfile.write('\n{% include ' + str(last_updated_file) + ' %}')
if jekyll_output:
outfile.write('\n{% include ' + str(last_updated_file) + ' %}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mark-Simulacrum what you want is for the {%include ... %} directive to be removed, right? Do you still want the last_updated_file info be in the output somehow?

outfile.close()

# writes the Jekyll header info for the index page for a given stream.
Expand Down Expand Up @@ -171,7 +177,8 @@ def write_topic_index(stream_name, stream):
datetime.utcfromtimestamp(t['latest_date']).strftime('%b %d %Y at %H:%M'),
'' if t['size'] == 1 else 's'
))
outfile.write('\n{% include ' + str(last_updated_file) + ' %}')
if jekyll_output:
outfile.write('\n{% include ' + str(last_updated_file) + ' %}')
outfile.close()

# formats the header for a topic page.
Expand Down Expand Up @@ -230,10 +237,12 @@ def write_topic(stream_name, stream, topic_name):
f.close()
o = open_outfile(md_root / Path(sanitize_stream(stream_name, stream['id'])), Path(sanitize_topic(topic_name) + '.html'), 'w+')
write_topic_header(o, stream_name, stream['id'], topic_name)
o.write('\n{% raw %}\n')
if jekyll_output:
o.write('\n{% raw %}\n')
write_topic_body(messages, stream_name, stream['id'], topic_name, o)
o.write('\n{% endraw %}\n')
o.write('\n{% include ' + str(last_updated_file) + ' %}')
if jekyll_output:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mark-Simulacrum is this what you wanted?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that in non-Jekyll mode we literally include the contents instead of via an include statement. That does mean that all of the files will change on each run, but that's true if you render through jekyll to a static site anyway.

o.write('\n{% endraw %}\n')
o.write('\n{% include ' + str(last_updated_file) + ' %}')
o.close()


Expand Down