Skip to content

Commit

Permalink
Link to named feeds on the homepage (#113)
Browse files Browse the repository at this point in the history
* Move search feed config loading to main

* Display feeds on home page

* Reduced rendered whitespace

* Reduce whitespace in lists template

* Reduced whitespace in twitter list

* Reduced whitespace on list page

* Reduced whitespace on list recommendation page

* Reduced whitespace on related articles page

* Reduced whitespace on article page

* Added feeds page

* Link to feeds page from home page

* Only display three feeds on home page
  • Loading branch information
de-code authored Jun 15, 2023
1 parent 4432eef commit 39bfb18
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 85 deletions.
10 changes: 8 additions & 2 deletions sciety_labs/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sciety_labs.app.utils.common import (
get_page_title
)
from sciety_labs.config.search_feed_config import load_search_feeds_config
from sciety_labs.config.site_config import get_site_config_from_environment_variables

from sciety_labs.utils.datetime import (
Expand Down Expand Up @@ -47,6 +48,9 @@ def create_app(): # pylint: disable=too-many-locals, too-many-statements
site_config = get_site_config_from_environment_variables()
LOGGER.info('site_config: %r', site_config)

search_feeds_config = load_search_feeds_config('config/search-feeds.yaml')
LOGGER.info('search_feeds_config: %r', search_feeds_config)

update_interval_in_secs = 60 * 60 # 1 hour
min_article_count = 2

Expand All @@ -73,7 +77,8 @@ def create_app(): # pylint: disable=too-many-locals, too-many-statements
app.include_router(create_home_router(
app_providers_and_models=app_providers_and_models,
min_article_count=min_article_count,
templates=templates
templates=templates,
search_feeds_config=search_feeds_config
))
app.include_router(create_lists_router(
app_providers_and_models=app_providers_and_models,
Expand All @@ -86,7 +91,8 @@ def create_app(): # pylint: disable=too-many-locals, too-many-statements
))
app.include_router(create_search_router(
app_providers_and_models=app_providers_and_models,
templates=templates
templates=templates,
search_feeds_config=search_feeds_config
))

@app.exception_handler(404)
Expand Down
7 changes: 5 additions & 2 deletions sciety_labs/app/routers/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi.templating import Jinja2Templates

from sciety_labs.app.app_providers_and_models import AppProvidersAndModels
from sciety_labs.config.search_feed_config import SearchFeedsConfig


LOGGER = logging.getLogger(__name__)
Expand All @@ -13,7 +14,8 @@
def create_home_router(
app_providers_and_models: AppProvidersAndModels,
templates: Jinja2Templates,
min_article_count: int
min_article_count: int,
search_feeds_config: SearchFeedsConfig
):
router = APIRouter()

Expand Down Expand Up @@ -43,7 +45,8 @@ def index(request: Request):
'pages/index.html', {
'request': request,
'user_lists': user_list_summary_data_list,
'group_lists': group_list_summary_data_list
'group_lists': group_list_summary_data_list,
'search_feeds': list(search_feeds_config.feeds_by_slug.values())[:3]
}
)

Expand Down
21 changes: 16 additions & 5 deletions sciety_labs/app/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from sciety_labs.app.app_providers_and_models import AppProvidersAndModels
from sciety_labs.app.utils.common import (
AnnotatedPaginationParameters,
get_page_title,
get_rss_url
)
from sciety_labs.app.utils.response import AtomResponse
from sciety_labs.config.search_feed_config import SearchFeedConfig, load_search_feeds_config
from sciety_labs.config.search_feed_config import SearchFeedConfig, SearchFeedsConfig
from sciety_labs.models.article import ArticleSearchResultItem, iter_preprint_article_mention
from sciety_labs.models.image import ObjectImages
from sciety_labs.providers.europe_pmc import EUROPE_PMC_PREPRINT_SERVERS
Expand Down Expand Up @@ -230,11 +231,9 @@ def get_search_result_template_parameters(

def create_search_router(
app_providers_and_models: AppProvidersAndModels,
templates: Jinja2Templates
templates: Jinja2Templates,
search_feeds_config: SearchFeedsConfig
):
search_feeds_config = load_search_feeds_config('config/search-feeds.yaml')
LOGGER.info('search_feeds_config: %r', search_feeds_config)

router = APIRouter()

@router.get('/search', response_class=HTMLResponse)
Expand Down Expand Up @@ -318,6 +317,18 @@ def _render_search_feed_atom_xml(
status_code=search_result_page.status_code
)

@router.get('/feeds', response_class=HTMLResponse)
def search_feeds(
request: Request
):
return templates.TemplateResponse(
'pages/search-feeds.html', {
'request': request,
'page_title': get_page_title('Feeds'),
'search_feeds': search_feeds_config.feeds_by_slug.values()
}
)

@router.get('/feeds/search', response_class=HTMLResponse)
def search_feed(
request: Request,
Expand Down
2 changes: 2 additions & 0 deletions sciety_labs/config/search_feed_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


class SearchFeedConfig(NamedTuple):
slug: str
title: str
description: str
image_url: str
Expand All @@ -23,6 +24,7 @@ def load_search_feeds_config(
return SearchFeedsConfig(
feeds_by_slug={
feed_dict['slug']: SearchFeedConfig(
slug=feed_dict['slug'],
title=feed_dict['title'],
description=feed_dict['description'],
image_url=feed_dict['image_url'],
Expand Down
37 changes: 19 additions & 18 deletions templates/pages/article-by-article-doi.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{% from 'macros/page.html' import render_page with context %}
{% from 'macros/article.html' import render_article_list_content with context %}
{% from 'macros/date.html' import render_optional_date_value_with_label %}
{% call render_page() %}
{%- from 'macros/page.html' import render_page with context %}
{%- from 'macros/article.html' import render_article_list_content with context %}
{%- from 'macros/date.html' import render_optional_date_value_with_label %}

{%- call render_page() %}
<main class="page-content" id="mainContent">

<div class="sciety-grid-two-columns">
<header class="page-header page-header--article">
{% if article_images and article_images.image_url %}
{%- if article_images and article_images.image_url %}
<img
src="{{ article_images.image_url }}"
alt="Striking image (AI generated)"
class="article__striking_image"
>
{% endif %}
{%- endif %}

<h1>{{ article_meta.article_title | sanitize }}</h1>

{% if article_meta.author_name_list %}
{%- if article_meta.author_name_list %}
<ol aria-label="Authors of this article" class="article-author-list" role="list">
{% for author_name in article_meta.author_name_list %}
{%- for author_name in article_meta.author_name_list %}
<li>{{ author_name }}</li>
{% endfor %}
{%- endfor %}
</ol>
{% endif %}
{%- endif %}

<section class="article-stats">
<div class="article-card__meta">
{% if article_stats %}
{%- if article_stats %}
<span class="visually-hidden">This article has </span><span>{{ article_stats.evaluation_count }} evaluations</span>
{% endif %}
{%- endif %}
{{ render_optional_date_value_with_label('Published on', article_meta.published_date) }}
{{ render_optional_date_value_with_label('Added on', created_at_timestamp) }}
</div>
Expand All @@ -43,29 +44,29 @@ <h1>{{ article_meta.article_title | sanitize }}</h1>
</div>
</div>

{% if article_meta.abstract %}
{%- if article_meta.abstract %}
<section role="doc-abstract" class="article-abstract">
<h2>Abstract</h2>
<div>
{{ article_meta.abstract | sanitize }}
</div>
</section>
{% endif %}
{%- endif %}

{% if article_recommendation_list %}
{%- if article_recommendation_list %}
<section id="article-recommendations">
<h2><a href="{{ article_recommendation_url }}">Related articles</a></h2>
{{ render_article_list_content(article_recommendation_list) }}
<a href="{{ article_recommendation_url }}">More</a>
</section>
{% else %}
{%- else %}
<section id="article-recommendations">
<h2>Related articles</h2>
<p>Related articles are currently not available for this article.</p>
</section>
{% endif %}
{%- endif %}

</div>

</main>
{% endcall %}
{%- endcall %}
19 changes: 10 additions & 9 deletions templates/pages/article-recommendations-by-article-doi.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% from 'macros/page.html' import render_page with context %}
{% from 'macros/article.html' import render_article_list_content with context %}
{% from 'macros/pagination.html' import render_pagination_header, render_pagination %}
{% call render_page() %}
{%- from 'macros/page.html' import render_page with context %}
{%- from 'macros/article.html' import render_article_list_content with context %}
{%- from 'macros/pagination.html' import render_pagination_header, render_pagination %}

{%- call render_page() %}
<main class="page-content" id="mainContent">
<div class="sciety-grid-two-columns">
<header class="page-header page-header--list">
Expand All @@ -17,19 +18,19 @@ <h1>Article Recommendations for
as related content to
<a href="/articles/by?article_doi={{ article_meta.article_doi }}">{{ article_meta.article_title | sanitize }}</a>
</span>
{% if article_meta.author_name_list %}
{%- if article_meta.author_name_list %}
<span> by
<ol
class="card-authors"
role="list"
aria-describedby="article-card-author-list-{{ article_meta.article_doi }}"
>
{% for author_name in article_meta.author_name_list %}
{%- for author_name in article_meta.author_name_list %}
<li class="card-authors__author">{{ author_name }}</li>
{% endfor %}
{%- endfor %}
</ol>
</span>
{% endif %}
{%- endif %}
</div>

<section>
Expand All @@ -44,4 +45,4 @@ <h1>Article Recommendations for
</section>
</div>
</main>
{% endcall %}
{%- endcall %}
11 changes: 6 additions & 5 deletions templates/pages/article-recommendations-by-sciety-list-id.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% from 'macros/page.html' import render_page with context %}
{% from 'macros/article.html' import render_article_list_content with context %}
{% from 'macros/pagination.html' import render_pagination_header, render_pagination %}
{% call render_page() %}
{%- from 'macros/page.html' import render_page with context %}
{%- from 'macros/article.html' import render_article_list_content with context %}
{%- from 'macros/pagination.html' import render_pagination_header, render_pagination %}

{%- call render_page() %}
<main class="page-content" id="mainContent">
<div class="sciety-grid-two-columns">
<header class="page-header page-header--list">
Expand Down Expand Up @@ -40,4 +41,4 @@ <h1>Article Recommendations for
</section>
</div>
</main>
{% endcall %}
{%- endcall %}
32 changes: 28 additions & 4 deletions templates/pages/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% from 'macros/page.html' import render_page with context %}
{% from 'macros/date.html' import render_optional_date_value_with_label %}
{% macro render_list_cards(lists) -%}
{%- from 'macros/page.html' import render_page with context %}
{%- from 'macros/date.html' import render_optional_date_value_with_label %}

{%- macro render_list_cards(lists) -%}
<ul class="home-page-cards__cards">
{% for item in lists %}
<li>
Expand All @@ -27,7 +28,8 @@ <h3 class="user-list-card__title">{{ item.list_meta.list_name }}</h3>
{% endfor %}
</ul>
{%- endmacro %}
{% call render_page(page_container_class='home-page-container') %}

{%- call render_page(page_container_class='home-page-container') %}

<main id="mainContent">

Expand Down Expand Up @@ -57,5 +59,27 @@ <h2 class="home-page-cards__title"><a href="/lists/group-lists">Most active grou
<a href="/lists/group-lists">More</a>
</section>

<section class="home-page-cards">
<h2 class="home-page-cards__title"><a href="/feeds">Top feeds</a></h2>
<ul class="home-page-cards__cards">
{% for item in search_feeds %}
<li>
<a href="/feeds/by-name/{{ item.slug }}" class="user-list-card__link">
<article class="user-list-card">
<div class="user-list-card__body">
<div>
<img class="user-list-card__list-image" src="{{ item.image_url }}" alt="" />
<h3 class="user-list-card__title">{{ item.title }}</h3>
<p>{{ item.description }}</p>
</div>
</div>
</article>
</a>
</li>
{% endfor %}
</ul>
<a href="/feeds">More</a>
</section>

</main>
{% endcall %}
26 changes: 13 additions & 13 deletions templates/pages/list-by-sciety-list-id.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{% from 'macros/page.html' import render_page with context %}
{% from 'macros/article.html' import render_article_list_content with context %}
{% from 'macros/pagination.html' import render_pagination_header, render_pagination %}
{% from 'macros/date.html' import render_optional_date_value_with_label %}
{%- from 'macros/page.html' import render_page with context %}
{%- from 'macros/article.html' import render_article_list_content with context %}
{%- from 'macros/pagination.html' import render_pagination_header, render_pagination %}
{%- from 'macros/date.html' import render_optional_date_value_with_label %}

{% call render_page() %}
{%- call render_page() %}
<main class="page-content" id="mainContent">
<div class="sciety-grid-two-columns">
<header class="page-header page-header--list">
{% if list_images and list_images.image_url %}
{%- if list_images and list_images.image_url %}
<img
src="{{ list_images.image_url }}"
alt="List image (AI generated)"
class="page-header__list-image"
>
{% endif %}
{%- endif %}

<div>
<h1>{{ list_summary_data.list_meta.list_name }}</h1>

<p class="page-header__subheading">
{% if list_summary_data.owner.avatar_url %}
{%- if list_summary_data.owner.avatar_url %}
<img src="{{ list_summary_data.owner.avatar_url }}" alt="" class="page-header__avatar">
{% endif %}
{% if owner_url %}
{%- endif %}
{%- if owner_url %}
<span>A list by <a href="{{ owner_url }}">{{ list_summary_data.owner.display_name }}</a></span>
{% else %}
{%- else %}
<span>A list by {{ list_summary_data.owner.display_name }}</span>
{% endif %}
{%- endif %}
</p>

<p class="page-header__description">{{ list_summary_data.list_meta.list_description }}</p>
Expand Down Expand Up @@ -55,4 +55,4 @@ <h1>{{ list_summary_data.list_meta.list_name }}</h1>
</section>
</div>
</main>
{% endcall %}
{%- endcall %}
Loading

0 comments on commit 39bfb18

Please sign in to comment.