Skip to content
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

added news Website #972

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 50 additions & 0 deletions Public/News_Website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>News from around the globe every day</title>
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#" style="font-weight: bold;">Daily News</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<div class="container" style="margin-top: 20px;">
<h3>Latest News by: <span class="badge bg-warning text-dark">Daily News</span></h3>
<br>
<div style="display: flex; align-items: center; margin: auto; text-align: center; justify-content: center;">
<div id="accordian"
style="max-width: 800px; text-align: center; align-items: center; justify-content: center;">
</div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script src="main.js"></script>
</body>

</html>
35 changes: 35 additions & 0 deletions Public/News_Website/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
console.log("Hello World!");

let newsAccordian = document.getElementById('accordian');
let country = 'in';
let apiKey = 'b598648722f84619b927f4e38f64aed3';

const xhr = new XMLHttpRequest();
xhr.open('GET', `https://newsapi.org/v2/top-headlines?country=${country}&apiKey=${apiKey}`, true);

xhr.onload = function () {
let json = JSON.parse(this.responseText);
console.log(json);
let articles = json.articles;
let newsHtml = "";
articles.forEach(function (element, index) {
let news = `<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#multiCollapseExample${index}" role="button" aria-expanded="false" aria-controls="multiCollapseExample${index}">${element['title']}</a>
<div class="row">
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample${index}">
<div class="card card-body" >
${element['description']}<a href="${element['url']}" target="_blank">Read more</a>
<img src="${element['urlToImage']}" alt="">
</div>
</div>
</div>
</div>
</p>`;
newsHtml += news;
});
newsAccordian.innerHTML = newsHtml;
console.log(articles);
}

xhr.send();
Loading