Skip to content

Commit

Permalink
[blog] add RSS feed (#12064)
Browse files Browse the repository at this point in the history
* [blog] add rss feed

* better title
  • Loading branch information
blinkov committed Jun 30, 2020
1 parent 948af0b commit e48b6b8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
10 changes: 9 additions & 1 deletion docs/tools/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def build_for_lang(lang, args):
includes_dir=os.path.join(os.path.dirname(__file__), '..', '_includes'),
is_amp=False,
is_blog=True,
post_meta=post_meta
post_meta=post_meta,
today=datetime.date.today().isoformat()
)
)

Expand All @@ -89,6 +90,13 @@ def build_for_lang(lang, args):

redirects.build_blog_redirects(args)

env = util.init_jinja2_env(args)
with open(os.path.join(args.website_dir, 'templates', 'blog', 'rss.xml'), 'rb') as f:
rss_template_string = f.read().decode('utf-8').strip()
rss_template = env.from_string(rss_template_string)
with open(os.path.join(args.blog_output_dir, lang, 'rss.xml'), 'w') as f:
f.write(rss_template.render({'config': raw_config}))

# TODO: AMP for blog
# if not args.skip_amp:
# amp.build_amp(lang, args, cfg)
Expand Down
9 changes: 2 additions & 7 deletions docs/tools/mdx_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

import slugify as slugify_impl

import amp
import website


def slugify(value, separator):
return slugify_impl.slugify(value, separator=separator, word_boundary=True, save_order=True)
Expand Down Expand Up @@ -119,17 +116,15 @@ def on_config(self, config):
])

def on_env(self, env, config, files):
import util
env.add_extension('jinja2.ext.i18n')
dirname = os.path.join(config.data['theme'].dirs[0], 'locale')
lang = config.data['theme']['language']
env.install_gettext_translations(
get_translations(dirname, lang),
newstyle=True
)
chunk_size = 10240
env.filters['chunks'] = lambda line: [line[i:i+chunk_size] for i in range(0, len(line), chunk_size)]
env.filters['html_to_amp'] = amp.html_to_amp
env.filters['adjust_markdown_html'] = website.adjust_markdown_html
util.init_jinja2_filters(env)
return env

def render(self, markdown):
Expand Down
34 changes: 34 additions & 0 deletions docs/tools/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import contextlib
import datetime
import multiprocessing
import os
import shutil
Expand All @@ -8,6 +9,7 @@
import tempfile
import threading

import jinja2
import yaml


Expand Down Expand Up @@ -111,3 +113,35 @@ def represent_ordereddict(dumper, data):


yaml.add_representer(collections.OrderedDict, represent_ordereddict)


def init_jinja2_filters(env):
import amp
import website
chunk_size = 10240
env.filters['chunks'] = lambda line: [line[i:i + chunk_size] for i in range(0, len(line), chunk_size)]
env.filters['html_to_amp'] = amp.html_to_amp
env.filters['adjust_markdown_html'] = website.adjust_markdown_html
env.filters['to_rfc882'] = lambda d: datetime.datetime.strptime(d, '%Y-%m-%d').strftime('%a, %d %b %Y %H:%M:%S GMT')


def init_jinja2_env(args):
import mdx_clickhouse
env = jinja2.Environment(
loader=jinja2.FileSystemLoader([
args.website_dir,
os.path.join(args.docs_dir, '_includes')
]),
extensions=[
'jinja2.ext.i18n',
'jinja2_highlight.HighlightExtension'
]
)
env.extend(jinja2_highlight_cssclass='syntax p-3 my-3')
translations_dir = os.path.join(args.website_dir, 'locale')
env.install_gettext_translations(
mdx_clickhouse.get_translations(translations_dir, 'en'),
newstyle=True
)
init_jinja2_filters(env)
return env
20 changes: 2 additions & 18 deletions docs/tools/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import closure
import cssmin
import htmlmin
import jinja2
import jsmin

import mdx_clickhouse
import util


def handle_iframe(iframe, soup):
Expand Down Expand Up @@ -121,22 +120,7 @@ def minify_html(content):

def build_website(args):
logging.info('Building website')
env = jinja2.Environment(
loader=jinja2.FileSystemLoader([
args.website_dir,
os.path.join(args.docs_dir, '_includes')
]),
extensions=[
'jinja2.ext.i18n',
'jinja2_highlight.HighlightExtension'
]
)
env.extend(jinja2_highlight_cssclass='syntax p-3 my-3')
translations_dir = os.path.join(args.website_dir, 'locale')
env.install_gettext_translations(
mdx_clickhouse.get_translations(translations_dir, 'en'),
newstyle=True
)
env = util.init_jinja2_env(args)

shutil.copytree(
args.website_dir,
Expand Down
23 changes: 23 additions & 0 deletions website/templates/blog/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>{{ config.site_name }}</title>
<link>{{ config.site_url }}</link>
<atom:link href="{{ config.site_url }}rss.xml" rel="self" type="application/rss+xml" />
<description></description>
<pubDate>{{ config.extra.today|to_rfc882 }}</pubDate>

{% for post in config.extra.post_meta.values() %}
{% set url = config.extra.website_url + post['url'] %}
<item>
<title>{{ post['title'] }}</title>
<description><![CDATA[<img src="{{ post['image'] }}" />]]></description>
<pubDate>{{ post['date']|to_rfc882 }}</pubDate>
<guid isPermaLink="true">{{ url }}</guid>
<link>{{ url }}</link>
{# TODO: <dc:creator><![CDATA[{{ post['author'] }}]]></dc:creator> #}
</item>
{% endfor %}
</channel>
</rss>
6 changes: 5 additions & 1 deletion website/templates/common_meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<meta name="description" content="{{ description }}" />
{% if page and page.meta.tags %}
<meta name="keywords"
content="{% for tag in page.meta.tags%}{{tag}}{{ ', ' if not loop.last }}{% endfor %}" />
content="{% for tag in page.meta.tags %}{{tag}}{{ ', ' if not loop.last }}{% endfor %}" />
{% else %}
<meta name="keywords"
content="ClickHouse, DBMS, OLAP, SQL, {{ _('open-source') }}, {{ _('relational') }}, {{ _('analytics') }}, {{ _('analytical') }}, {{ _('Big Data') }}, {{ _('web-analytics') }}" />
Expand All @@ -45,3 +45,7 @@
{% for prefetch_item in prefetch_items %}
<link rel="prefetch" href="{{ prefetch_item.0 }}" as="{{ prefetch_item.1 }}" />
{% endfor %}

{% if is_blog %}
<link rel="alternate" type="application/rss+xml" href="{{ config.site_url }}rss.xml" />
{% endif %}

0 comments on commit e48b6b8

Please sign in to comment.