Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Created November 8, 2023 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjarneo/543924244200e5deaaf994bf09a6374d to your computer and use it in GitHub Desktop.
Save bjarneo/543924244200e5deaaf994bf09a6374d to your computer and use it in GitHub Desktop.
norwaytimes2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Norway Times - Article List</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f3f3f3;
margin: 0;
padding: 0;
}
.container {
width: 60%;
margin: 0 auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-top: 20px;
}
h1 {
text-align: center;
color: #333;
}
.article-list {
list-style: none;
padding: 0;
}
.article-list-item {
margin-bottom: 20px;
}
.article-title {
font-size: 1.2em;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>Norway Times</h1>
<ul class="article-list"></ul>
</div>
<script>
const API = 'https://www.vg.no/feed/latest';
const articleList = document.querySelector('.article-list');
const getArticles = async () => {
const response = await fetch(API);
const data = await response.json();
return data;
};
getArticles()
.then((articles) => {
articles.forEach((article) => {
const articleListItem = document.createElement('li');
articleListItem.classList.add('article-list-item');
const articleTitle = document.createElement('h2');
articleTitle.classList.add('article-title');
articleTitle.textContent = article.title;
const articleDescription = document.createElement('p');
articleDescription.classList.add('article-description');
articleDescription.textContent = article.description;
// Legg inn bilde i HTML
// article.images[0].url
articleListItem.appendChild(articleTitle);
articleListItem.appendChild(articleDescription);
articleList.innerHTML += articleListItem.outerHTML;
});
})
.catch(console.error);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment