-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new component <ArticleFooter/> * Apply <ArticleFooter/> in <Article/> and toc * Adjustable font size in Footer section * Prefetch article footer suggested article items * Fix error when the suggested article return empty query * Rename getArticleFooter -> getSuggestedArticles * use isFooter to render <ArticleFooter/> and minor changes
- Loading branch information
Showing
14 changed files
with
247 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { buildMwApiUrl, cachedFetch } from 'utils' | ||
|
||
export const getSuggestedArticles = (lang, title) => { | ||
const params = { | ||
action: 'query', | ||
prop: 'pageimages|description', | ||
piprop: 'thumbnail', | ||
pithumbsize: 160, | ||
pilimit: 3, | ||
generator: 'search', | ||
gsrsearch: `morelike:${title}`, | ||
gsrnamespace: 0, | ||
gsrlimit: 3, | ||
gsrqiprofile: 'classic_noboostlinks', | ||
uselang: 'content' | ||
} | ||
|
||
const url = buildMwApiUrl(lang, params) | ||
return cachedFetch(url, data => data.query && data.query.pages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { h } from 'preact' | ||
import { useI18n } from 'hooks' | ||
import { buildWpMobileWebUrl } from 'utils' | ||
|
||
export const ArticleFooter = ({ lang, title, items = [] }) => { | ||
const i18n = useI18n() | ||
|
||
return ( | ||
<div class='article-footer'> | ||
<div class='content'> | ||
<h2 class='adjustable-font-size'>{i18n.i18n('suggested-articles')}</h2> | ||
<div class='list'> | ||
{ items.map(item => { | ||
return ( | ||
<a class='item' title={item.title} key={item.title}> | ||
<div class='info'> | ||
<div class='article-title adjustable-font-size'>{item.title}</div> | ||
<div class='description adjustable-font-size'>{item.description}</div> | ||
</div> | ||
{ item.thumbnail && <div class='img'><img src={item.thumbnail.source} /></div> } | ||
</a> | ||
) | ||
})} | ||
</div> | ||
<h2 class='img'> | ||
<img src='/images/wikipedia-wordmark-en.png' height='18' width='116' /> | ||
</h2> | ||
<p class='license adjustable-font-size' dangerouslySetInnerHTML={{ __html: i18n.i18n('content-license') }} /> | ||
<p class='browser'> | ||
<a class='external adjustable-font-size' rel='mw:ExtLink' href={buildWpMobileWebUrl(lang, title)}> | ||
{i18n.i18n('view-in-browser')} | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import { useState, useEffect } from 'preact/hooks' | ||
import { getArticle } from 'api' | ||
|
||
export const useArticle = (lang, title) => { | ||
const [article, setArticle] = useState() | ||
|
||
useEffect(() => { | ||
getArticle(lang, title) | ||
.then((article) => setArticle(article)) | ||
}, [lang, title]) | ||
|
||
return article | ||
import { useState, useEffect } from 'preact/hooks' | ||
import { useI18n } from 'hooks' | ||
import { getArticle, getSuggestedArticles } from 'api' | ||
|
||
export const useArticle = (lang, title) => { | ||
const [article, setArticle] = useState() | ||
const i18n = useI18n() | ||
|
||
useEffect(() => { | ||
Promise.all([getArticle(lang, title), getSuggestedArticles(lang, title)]) | ||
.then(([article, suggestedArticles]) => { | ||
const { sections, toc } = article | ||
|
||
// build footer used section and toc | ||
const sectionsWithFooter = sections.concat({ | ||
title: i18n.i18n('toc-footer'), | ||
imageUrl: false, | ||
isFooter: true | ||
}) | ||
const tocWithFooter = toc.concat({ level: 1, line: i18n.i18n('toc-footer'), sectionIndex: sectionsWithFooter.length - 1 }) | ||
|
||
setArticle({ ...article, sections: sectionsWithFooter, toc: tocWithFooter, suggestedArticles }) | ||
}) | ||
}, [lang, title]) | ||
|
||
return article | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
.article-footer { | ||
font-family: @textFont; | ||
padding: 6px; | ||
background-color: #f5f5f5; | ||
|
||
.content { | ||
h2 { | ||
color: #54595d; | ||
border-bottom: 0; | ||
padding: 0.5em 0; | ||
font-size: 0.8em; | ||
font-weight: normal; | ||
letter-spacing: 1px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.list { | ||
width: 100%; | ||
|
||
a.item { | ||
height: 59px; | ||
margin: 10px 0; | ||
padding: 6px 10px; | ||
display: flex; | ||
justify-content: space-between; | ||
border-radius: 5px; | ||
background-color: #fff; | ||
box-shadow: -2px 2px 10px 0 rgba( 0, 0, 0, 0.1 ); | ||
border: solid 1px #f5f5f5; | ||
|
||
&[ data-selected='true' ] { | ||
background-color: #eaf3ff; | ||
} | ||
|
||
.info { | ||
font-family: @textFont; | ||
height: 100%; | ||
overflow: hidden; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
|
||
.article-title { | ||
font-size: 15px; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
|
||
.description { | ||
font-size: 12px; | ||
color: @colorLight; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
} | ||
|
||
.img { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
|
||
img { | ||
width: 38px; | ||
height: 38px; | ||
border-radius: 4px; | ||
} | ||
} | ||
|
||
.link { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
} | ||
|
||
&[ nav-selected=true ] { | ||
background-color: #eaf3ff; | ||
} | ||
} | ||
} | ||
} | ||
|
||
h2 { | ||
padding-bottom: 10px; | ||
padding-top: 20px; | ||
margin: 0; | ||
|
||
&.img { | ||
padding: 20px 0 15px; | ||
border-bottom: solid 1px #c8ccd1; | ||
} | ||
} | ||
|
||
.license, | ||
.browser { | ||
font-size: 0.75em; | ||
margin-bottom: 10px; | ||
line-height: normal; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
padding: 1px; | ||
} | ||
} |
Oops, something went wrong.