Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions README.md
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"/>
34 changes: 34 additions & 0 deletions index.html
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>
44 changes: 44 additions & 0 deletions index.js
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)
Copy link
Contributor

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

.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
Copy link
Contributor

Choose a reason for hiding this comment

The 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> &nbsp&nbsp&nbsp 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;
}
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php header( 'Location: /index.html' ) ; ?>
120 changes: 120 additions & 0 deletions myCSS.css
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;
}
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.