Skip to content

Commit

Permalink
Merge pull request #32 from 1mace1/fix/core/empty-list-of-articles-ca…
Browse files Browse the repository at this point in the history
…use-index-error

Fixed IndexError when the list of articles is empty (#31)
  • Loading branch information
PhilippeTrounev authored Jul 19, 2021
2 parents cd9496d + 55242aa commit 0c4cefe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/blog_vi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ def generate(self, filename: str = 'index.html', is_category: bool = False):
template = env.get_template(self.template)

template_categories = {(category, f'{slugify(category)}.html') for category in self._categories.keys()}
head_article = self._articles[0] if self._articles else None

rendered = template.render(
blogs=self._articles[1:],
head_blog=self._articles[0],
head_blog=head_article,
categories=template_categories,
searchConfig=self.search_config,
settings=self.settings
Expand Down
52 changes: 27 additions & 25 deletions src/blog_vi/templates/base_landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,39 @@
<div class="w-full text-xl md:text-2xl text-gray-800 leading-normal rounded-t">

<!--Lead Card-->
<div class="flex h-full bg-white rounded overflow-hidden ">
<a href="{{ head_blog.path }}" class="flex flex-wrap no-underline hover:no-underline">
<div class="w-full md:w-2/3 rounded-t">
<img src="{{head_blog.header_image}}" class="h-full w-full shadow object-cover">
</div>

<div class="w-full md:w-1/3 flex flex-col flex-grow flex-shrink">
<div class="flex-1 bg-white rounded-t rounded-b-none overflow-hidden ">
<p class="w-full text-gray-600 text-xs md:text-sm pt-6 px-6">GETTING STARTED</p>
<div class="w-full font-bold text-xl text-gray-900 px-6">{{head_blog.title}}
</div>
<p class="text-gray-800 font-serif text-base px-6 mb-5">
{{ head_blog.summary }}
</p>
{% if head_blog %}
<div class="flex h-full bg-white rounded overflow-hidden ">
<a href="{{ head_blog.path }}" class="flex flex-wrap no-underline hover:no-underline">
<div class="w-full md:w-2/3 rounded-t">
<img src="{{head_blog.header_image}}" class="h-full w-full shadow object-cover">
</div>

<div class="flex-none mt-auto bg-white rounded-b rounded-t-none overflow-hidden p-6">
<div class="flex items-center justify-between">
<img class="w-8 h-8 rounded-full mr-4 avatar" data-tippy-content="{{ head_blog.author_name }}"
src="{{ head_blog.author_image }}" alt="{{ head_blog.author_name }}">
<p class="text-gray-600 text-xs md:text-sm">
{% for ctg in head_blog.categories%}
{{ ctg }}
{% endfor %}
<div class="w-full md:w-1/3 flex flex-col flex-grow flex-shrink">
<div class="flex-1 bg-white rounded-t rounded-b-none overflow-hidden ">
<p class="w-full text-gray-600 text-xs md:text-sm pt-6 px-6">GETTING STARTED</p>
<div class="w-full font-bold text-xl text-gray-900 px-6">{{head_blog.title}}
</div>
<p class="text-gray-800 font-serif text-base px-6 mb-5">
{{ head_blog.summary }}
</p>
</div>

<div class="flex-none mt-auto bg-white rounded-b rounded-t-none overflow-hidden p-6">
<div class="flex items-center justify-between">
<img class="w-8 h-8 rounded-full mr-4 avatar" data-tippy-content="{{ head_blog.author_name }}"
src="{{ head_blog.author_image }}" alt="{{ head_blog.author_name }}">
<p class="text-gray-600 text-xs md:text-sm">
{% for ctg in head_blog.categories%}
{{ ctg }}
{% endfor %}
</p>
</div>
</div>
</div>
</div>

</a>
</div>
</a>
</div>
{% endif %}
<!--/Lead Card-->
<!-- {{ searchConfig }}-->

Expand Down

0 comments on commit 0c4cefe

Please sign in to comment.