-
Notifications
You must be signed in to change notification settings - Fork 34
Responsive-news-reader #8
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
Open
JuliusVai
wants to merge
8
commits into
constructorlabs:master
Choose a base branch
from
JuliusVai:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af61299
Initial commit
JuliusVai 746111e
Site ready for deployment.
JuliusVai 4a4b5f9
Update README.md
JuliusVai 73971ea
Update README.md
JuliusVai 961b31e
Update README.md
JuliusVai 3a564e8
added screenshot
JuliusVai 20ecdc1
changed readme
JuliusVai 5a49292
Update README.md
JuliusVai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 +1,13 @@ | ||
| # Responsive News Reader | ||
| ## Responsive News Reader | ||
|
|
||
| Let's create a responsive news reader website. To get the latest news the app will display we are going to use [News API](https://newsapi.org/). As with the Weather and Unsplash APIs, you will need to register with the service to obtain an API key. | ||
| ### Technologies used: | ||
|
|
||
| ## Objectives | ||
| - Javascript | ||
| - CSS flex | ||
| - External API | ||
|
|
||
| - [ ] Create a responsive layout that works well and looks good at mobile, tablet and desktop screen sizes. Please create the mobile version first, then tablet and then desktop. | ||
| News Reader - responsive website that displays 20 most popular news articles for a present time. | ||
|
|
||
| - [ ] Fetch news articles from News API and display them including title, image, description, publication, date and link to article. | ||
| Demo app // http://todays-top-news.herokuapp.com | ||
|
|
||
| - [ ] Display images for tablet and desktop screens only | ||
|
|
||
| - [ ] Implement a feature of your choice | ||
|
|
||
| ## Stretch goals | ||
|
|
||
| - [ ] Implement pagination which allows you to get the next 20 results and display them | ||
|
|
||
| - [ ] Add search functionality which allows the user to retrieve news about a particular topic | ||
|
|
||
| ## Instructions | ||
|
|
||
| - Fork and clone this repo | ||
| - Commit your changes frequently with short and descriptive commit messages | ||
| - Create a pull request when complete | ||
| - We want to see great looking webpages | ||
| - Your code should have consistent indentation and sensible naming | ||
| - Use lots of concise functions with a clear purpose | ||
| - Add code comments where it is not immediately obvious what your code does | ||
| - Your code should not throw errors and handle edge cases gracefully. For example not break if server fails to return expected results | ||
|
|
||
| ## README.md | ||
|
|
||
| When finished, include a README.md in your repo. This should explain what the project is, how to run it and how to use it. Someone who is not familiar with the project should be able to look at it and understand what it is and what to do with it. | ||
| <img width ="600px" src="./screenshot1.png" alt="screenshot1"/> |
This file contains hidden or 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,34 @@ | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <link rel="stylesheet" href="myCSS.css"> | ||
| <title>Document</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="container"> | ||
| <div class="header"> | ||
| <h1 class="header__logo">Top Articles Today</h1> | ||
| </div> | ||
|
|
||
| <div class="content"> | ||
| <div class="content__section1"></div> | ||
| <div id="news" class="content__section2">Section 2</div> | ||
| <div class="content__section3"></div> | ||
| </div> | ||
|
|
||
|
|
||
| <div class="footer"> | ||
| <div class="footer_section1"> | ||
| <a id="uptotop">Back to top of page</a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src="index.js" type="text/javascript"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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,44 @@ | ||
| const displayArticles = document.querySelector("#news"); | ||
|
|
||
| var url = `https://newsapi.org/v2/top-headlines?country=Gb&apiKey=fef23a6326874b0a8642a68a9dc15687`; | ||
| var req = new Request(url); | ||
| fetch(url) | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(data) { | ||
| console.log(data.articles); | ||
| displayNews(data); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log(error); | ||
| }); | ||
|
|
||
| function displayNews(data) { | ||
| const html = data.articles | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
| .map(function(news) { | ||
| return ` | ||
| <div class="article-container"><p class="titles"> | ||
| ${news.title} | ||
| </p> | ||
| <img class="images"src=${ | ||
| news.urlToImage | ||
| } alt="No article image available"> | ||
| <p>${news.description}</p> | ||
| <p><p> | ||
| <p><strong>Source:</strong> <a href=${ | ||
| news.url | ||
| }>${news.source.name}</a><strong>     Date of publication:</strong> ${news.publishedAt}<p> | ||
| </div> | ||
| `; | ||
| }) | ||
| .join(""); | ||
|
|
||
| const upToTop = document.querySelector("#uptotop"); | ||
|
|
||
| upToTop.addEventListener("click", function(event) { | ||
| window.scrollTo(0, 0); | ||
| }); | ||
|
|
||
| displayArticles.innerHTML = html; | ||
| } | ||
This file contains hidden or 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 @@ | ||
| <?php header( 'Location: /index.html' ) ; ?> |
This file contains hidden or 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,120 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; | ||
| } | ||
|
|
||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .header { | ||
| background-color: #ac2d25; | ||
| color: white; | ||
| display: flex; | ||
| flex-direction: column; | ||
| text-align: center; | ||
| padding: 10px; | ||
| height: 8vh; | ||
| } | ||
|
|
||
| .header__logo { | ||
| margin: 0; | ||
| font-weight: 600; | ||
| font-size: 220%; | ||
| } | ||
|
|
||
| .content { | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-evenly; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .content__section1 { | ||
| background-color: #f3f3ef; | ||
| flex: 1; | ||
| display: none; | ||
| } | ||
|
|
||
| .content__section2 { | ||
| flex: 10; | ||
| } | ||
|
|
||
| .content__section3 { | ||
| background-color: #f3f3ef; | ||
| display: none; | ||
| flex: 1; | ||
| } | ||
|
|
||
| .titles { | ||
| font-size: 180%; | ||
| padding: 0 100px 20px 100px; | ||
| } | ||
|
|
||
| .images { | ||
| display: none; | ||
| } | ||
|
|
||
| .article-container:nth-child(even) { | ||
| background-color: #f3f3f0; | ||
| } | ||
|
|
||
| .article-container { | ||
| padding-top: 20px; | ||
| padding-bottom: 20px; | ||
| } | ||
|
|
||
| #footer__back-to-top { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .footer { | ||
| position: fixed; | ||
| display: block; | ||
| bottom: 0; | ||
| width: 100%; | ||
| height: 3vh; | ||
| text-align: center; | ||
| background-color: black; | ||
| color: white; | ||
| flex: 1; | ||
| } | ||
|
|
||
| .footer_section1 { | ||
| } | ||
|
|
||
| @media (min-width: 768px) { | ||
| .images { | ||
| width: 650px; | ||
| display: inline-flex; | ||
| } | ||
|
|
||
| .content__section1 { | ||
| display: block; | ||
| } | ||
|
|
||
| .content__section3 { | ||
| display: block; | ||
| } | ||
|
|
||
| .content { | ||
| flex-direction: row; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 1200px) { | ||
| .images { | ||
| width: 950px; | ||
| } | ||
|
|
||
| .content__section3 { | ||
| flex: 1; | ||
| display: block; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass in the url directly to fetch without creating a Request