-
Notifications
You must be signed in to change notification settings - Fork 34
Working version of News Reader #25
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <!DOCTYPE html> | ||
| <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="style.css"> | ||
| <title>Document</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="topnav" class="flex-grid"> | ||
| <h3><a class="active" href="#home">Home</a></h3> | ||
| <h3><a href="#news">News</a></h3> | ||
| <h3><a href="#media">Media</a></h3> | ||
| </h3><input type="text" placeholder="Search.."></h3> | ||
| </div> | ||
| <div id="header" class=flex-grid> | ||
| <h1>The Daily News</h1> | ||
| </div> | ||
|
|
||
| <div class="site"> | ||
| <div id="article" class="wrapper"></div> | ||
| </div> | ||
|
|
||
|
|
||
| <script src="index.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| function displayData(articles) { | ||
| const stories = document.querySelector("#article"); | ||
| articles.map(article => { | ||
| let div = document.createElement("div"); | ||
|
Contributor
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. It might easier to implement this part using HTML string templates |
||
| stories.appendChild(div); | ||
|
|
||
| let title = document.createElement("h3"); | ||
| title.textContent = article.title; | ||
| div.appendChild(title); | ||
| image = document.createElement("img"); | ||
| image.setAttribute( | ||
| "src", | ||
| article.urlToImage || "http://placekitten.com/200/300" | ||
| ); | ||
| image.setAttribute("alt", article.title || "Nothing to see here"); | ||
| image.setAttribute("height", "100px"); | ||
| image.setAttribute("width", "150px"); | ||
| div.appendChild(image); | ||
|
|
||
| let description = document.createElement("h4"); | ||
| description.textContent = article.description; | ||
| div.appendChild(description); | ||
|
|
||
| let source = document.createElement("h5"); | ||
| source.textContent = article.source.name; | ||
| div.appendChild(source); | ||
|
|
||
| let datePublished = document.createElement("div"); | ||
| datePublished.textContent = article.publishedAt; | ||
| div.appendChild(datePublished); | ||
|
|
||
| let button = document.createElement("a"); | ||
| button.textContent = "Original Source"; | ||
| button.setAttribute("href", article.url); | ||
| div.appendChild(button); | ||
|
|
||
| // function articleSearch() { | ||
|
Contributor
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. Commented out code can be removed so it does not take up space on the page |
||
| // let input = document.getElementById("article.description").placeholder { | ||
|
|
||
| // } | ||
|
|
||
| // filter = input.value.toUpperCase(result); | ||
| // } | ||
|
|
||
| console.log( | ||
| "title :", | ||
| article.title, | ||
| "image ", | ||
| article.urlToImage, | ||
| "desc :", | ||
| article.description, | ||
| "source", | ||
| article.source.name, | ||
| "date", | ||
| article.publishedAt, | ||
| "link:", | ||
| article.url | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| fetch( | ||
| "https://newsapi.org/v2/top-headlines?country=gb&apiKey=b7b5bf6dda374f2086f391c826337994" | ||
| ) | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(body) { | ||
| console.log(body.articles); | ||
| displayData(body.articles); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log(error); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| .site { | ||
| background-color: whitesmoke; | ||
| padding: 5px; | ||
| flex-grow: 4; | ||
| } | ||
|
|
||
| #header { | ||
| display: flex; | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif; | ||
| font-size: 12px; | ||
| font-weight: 300; | ||
| padding: 1px; | ||
| align-content: space-between; | ||
| background-color: lightgrey; | ||
| } | ||
|
|
||
| #topnav { | ||
| display: flex; | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| text-align: center; | ||
| justify-content: space-evenly; | ||
| padding: 14px 16px; | ||
| flex-grow: inherit; | ||
| font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", | ||
| "Lucida Sans Unicode", Geneva, Verdana, sans-serif; | ||
| font-size: 12px; | ||
| background: lavender; | ||
| color: black; | ||
| } | ||
|
|
||
| .topnav a:hover { | ||
| color: red; | ||
| } | ||
| .topnav input[type="text"] { | ||
| float: right; | ||
| padding: 6px; | ||
| border: none; | ||
| margin-top: 8px; | ||
| margin-right: 16px; | ||
| font-size: 17px; | ||
| } | ||
|
|
||
| .wrapper { | ||
| display: grid; | ||
|
Contributor
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 to see grid being used |
||
| grid-template-columns: 50% 50%; | ||
| font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", | ||
| "Lucida Sans Unicode", Geneva, Verdana, sans-serif; | ||
| font-size: 12px; | ||
| } | ||
|
|
||
| .wrapper > div { | ||
| background: silver; | ||
| padding: 0.5em; | ||
| } | ||
|
|
||
| @media (max-width: 1024px) { | ||
| .wrapper { | ||
| grid-template-columns: 100; | ||
| } | ||
| } | ||
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.
If you don't use the output of a map method, it's better to replace it with a forEach instead