diff --git a/README.md b/README.md index f2e0c4a..4fbcf3d 100644 --- a/README.md +++ b/README.md @@ -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. +screenshot1 diff --git a/index.html b/index.html new file mode 100644 index 0000000..266dd4f --- /dev/null +++ b/index.html @@ -0,0 +1,34 @@ + + + + + + + + Document + + + +
+
+

Top Articles Today

+
+ +
+
+
Section 2
+
+
+ + + +
+ + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..74b37e5 --- /dev/null +++ b/index.js @@ -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 + .map(function(news) { + return ` +

+ ${news.title} +

+ No article image available +

${news.description}

+

+

Source: ${news.source.name}     Date of publication: ${news.publishedAt}

+

+ `; + }) + .join(""); + + const upToTop = document.querySelector("#uptotop"); + + upToTop.addEventListener("click", function(event) { + window.scrollTo(0, 0); + }); + + displayArticles.innerHTML = html; +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..b0e04b7 --- /dev/null +++ b/index.php @@ -0,0 +1 @@ + diff --git a/myCSS.css b/myCSS.css new file mode 100644 index 0000000..3bd8129 --- /dev/null +++ b/myCSS.css @@ -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; + } +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..d807436 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "lockfileVersion": 1, + "engines": { + "node": "10.7.0" + } +} diff --git a/screenshot1.png b/screenshot1.png new file mode 100644 index 0000000..6007c98 Binary files /dev/null and b/screenshot1.png differ