import axios from "axios" ; import { PostDetails } from "@/typings/blog" ; export const HIDE_NAVBAR_PAGES = [ "fancy-pants" ] ; const BUTTONDOWN_URL = "https://api.buttondown.email/v1/subscribers" ; const BUTTONDOWN_API_KEY = process . env . BUTTONDOWN_API_KEY ; param path export function checkIfNavbarShouldBeHidden ( path ) { return HIDE_NAVBAR_PAGES . includes ( path ) ; } type TButtondownSubscribersAPIResponseObject = { count : number ; next : null ; previous : null ; results : Array < { creation_date : string ; email : string ; id : string ; notes : string ; referrer_url : string ; metadata : Record < string , unknown > ; secondary_id : number ; subscriber_type : string ; source : string ; tags : Array < string > ; utm_campaign : string ; utm_medium : string ; utm_source : string ; } > ; } ; export async function getButtondownSubscriberCount ( ) { const BUTTONDOWN_AUTH_TOKEN = `Token ${ BUTTONDOWN_API_KEY }` ; try { return ( ( await axios . get ( BUTTONDOWN_URL , { headers : { Authorization : BUTTONDOWN_AUTH_TOKEN } , } ) ) . data as TButtondownSubscribersAPIResponseObject ) . count ; } catch ( error ) { return 69 ; } } param path returns export async function updateAndGetViewCount ( path ) { return ( await axios . post < Pick < PostDetails , "view_count" > > ( "/api/page/add-view" , { page_slug : path , } ) ) . data ; } param path returns export async function getViewCount ( path ) { return ( await axios . get < Pick < PostDetails , "view_count" > > ( "/api/page/get-views" , { params : { slug : path } , } ) ) . data ; }