Hello,
I am working on a project that requires me to setup a custom blog page. I have been able to implement the code necessary to assign data to UI elements for the Blog Title, Author Name and Published Date.
However, I have a couple of issues. First, the published date shows the full date and time such as “Mon Feb 06 2023 13:14:57 GMT-0500 (Eastern Standard Time)”. How can I reduce this to a shorter date format such as Feb 6, 2023?
Also, the Author Name displays some weird characters such as f709d22c-e50f-4a05-bceb-804a96b677a0. How can I get this to display the exact name such as Jane Doe?
Below is the current code I have to the page. I’ll appreciate any help fixing the two issues above while still being able to keep the data linked to the UI elements.
P. S. I don’t know coding. I usually just copy and paste
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
let currentPost
$w . onReady ( function () {
wixLocation . onChange (( location ) => {
initPage ()
});
initPage ()
})
async function initPage ( ) {
$w ( "#post1" ). getPost (). then ( **async** post => {
currentPost = **await** loadExtraPostData ( post )
assignPostDataToUIElements ()
});
}
async function loadExtraPostData ( post ) {
**let** postDataFromCollection = **await** wixData . query ( "PostExtraData" )
. eq ( "post" , post . _id )
. find ()
postDataFromCollection = postDataFromCollection . items [ 0 ]
**return** mergePostData ( post , postDataFromCollection )
}
async function mergePostData ( post , extraData ) {
return Object . assign ({}, post , extraData )
}
function assignPostDataToUIElements ( ) {
$w ( “#postTitle” ). text = currentPost . title
$w ( “#authorName” ). text = String ( currentPost . author )
$w ( “#publishedDate” ). text = String ( currentPost . publishedDate )
$w ( “#coverImage” ). src = currentPost . coverImage
}