/ Export can be used to share code between multiple javascript files
export const exportedText = "This paragraph was created with javascript";
export const config = {
postsDirectory: 'posts/',
posts: [
{
file: '1-First-Post',
title: 'My First Post',
date: '2024-12-15',
subtitle: 'This is a subtitle',
},
{
file: '2-Second-Post',
title: 'My Second Post',
date: '2024-12-18',
subtitle: 'This is another subtitle',
}
],
};
// Import is used to get code from other javascript files
import { config } from "./configs.js";
// This functions lists all blog posts
function listBlogPosts(){
// Get post listing div
const postsListingDiv = document.getElementById('posts-listing');
// Empty div content
postsListingDiv.innerHTML = '';
// Create unordered list
const postsList = document.createElement('ul');
postsList.className = 'posts-list';
// Get list of posts from configs.js
const posts = config.posts;
// If there are no posts, end code execution here
if(posts.length == 0){
return;
}
// Create a list item for each post
posts.forEach(post => {
const listItem = document.createElement('li');
listItem.className = 'post-item';
// Contents of the list item
listItem.innerHTML = `
${post.title}
${post.date}
${post.subtitle}
`;
postsList.appendChild(listItem);
})
// Add blog posts list to div
postsListingDiv.appendChild(postsList);
}
// Call a function to execute it
listBlogPosts();