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

Create a helper function to transform reading time and authors into a nice format. #49

Open
zberwaldt opened this issue Sep 4, 2021 · 3 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed Like to Have Low Priority Would be nice to fix, but low on the totem pole Polish Optional polish items.

Comments

@zberwaldt
Copy link
Contributor

zberwaldt commented Sep 4, 2021

When the website gets data from the cms we get objects like this:

{
  "posts": [
    {
     ...
      "url": "https://docs.ghost.io/welcome-short/",
      "excerpt": "👋 Welcome, it's great to have you here.",
      "reading_time": 0,
      "access": true,
      ...
    }
  ]
}

It would be nice to have a function that will take reading_time and transform it into a nice format. Kind of like in the following image:

image

Author data is also included. Implementing a string builder utility to present authors will be a nice polish item.

   "authors": [
        {
          "id": "5951f5fca366002ebd5dbef7",
          "name": "Ghost",
          "slug": "ghost",
          "profile_image": "https://demo.ghost.io/content/images/2017/07/ghost-icon.png",
          "cover_image": null,
          "bio": "The professional publishing platform",
          "website": "https://ghost.org",
          "location": null,
          "facebook": "ghost",
          "twitter": "@tryghost",
          "meta_title": null,
          "meta_description": null,
          "url": "https://demo.ghost.io/author/ghost/"
        }
      ],
@zberwaldt zberwaldt added good first issue Good for newcomers help wanted Extra attention is needed Like to Have Low Priority Would be nice to fix, but low on the totem pole Polish Optional polish items. labels Sep 4, 2021
@zberwaldt
Copy link
Contributor Author

the ghost library might have something for this already

https://ghost.org/docs/content-api/javascript/

start there, see if they work.

@zberwaldt zberwaldt changed the title Create a helper function to handle data from CMS and transform it to make it human readable. Create a helper function to transform reading time and authors into a nice format. Sep 7, 2021
@moshejs moshejs self-assigned this Oct 10, 2021
@moshejs
Copy link
Contributor

moshejs commented Oct 10, 2021

hey @zberwaldt - I checked the ghost library briefly and it doesn't appear to have the helper we want.

I immediately thought about momentjs but it's considered a legacy project now.

There's a maintained project date-fns that has a formatDistance helper

import { formatDistance, subDays } from 'date-fns'

formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"

@zberwaldt
Copy link
Contributor Author

@moshejs cool, let's give it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed Like to Have Low Priority Would be nice to fix, but low on the totem pole Polish Optional polish items.
Projects
None yet
Development

No branches or pull requests

2 participants