Options
All
  • Public
  • Public/Protected
  • All
Menu

nextjs-blog-lib

Index

Type aliases

MdxRenderType

MdxRenderType: React.FC<{ components: Record<string, any> }>

Variables

Const getAllPosts

getAllPosts: (Anonymous function) = memoize(async function (options: BlogOptions) {const slugs = getPostSlugs(options);return await Promise.all(slugs.map((slug) => getPostBySlug(slug, options)));})

Get a list of all posts.

Const getPostBySlug

getPostBySlug: (Anonymous function) = memoize(async function (slug: string,options: BlogOptions): Promise<Post> {const folderPath = join(options.postsDirectory, slug);const fullPath = join(folderPath, "index.mdx");const backupPath = join(folderPath, "index.md");let filePath;// Check if path is a folder or a fileif (fs.lstatSync(folderPath).isFile()) {filePath = folderPath;} else if (fs.existsSync(fullPath)) {filePath = fullPath;} else {filePath = backupPath;}const fileContents = fs.readFileSync(filePath, "utf8");const newContents = options.rewriteMediaUrls? rewriteMedias(folderPath,slug,fileContents,options.rewriteMediaUrls.mediaDirectory,options.rewriteMediaUrls.relativeDirectory): fileContents;const { data, content } = matter(newContents);const excerpt = createExcerpt(content, options);const { rendered: excerptRendered, code: excerptCode } =await createHtmlStringFromMarkdown(excerpt || "", options);const { rendered: contentRendered, code: contentCode } =await createHtmlStringFromMarkdown(content || "", options);const item: Post = {slug: slug,date: slug.split("-").slice(0, 3).join("-"),title: data["title"] ?? slug,frontmatter: data,contentRaw: content,contentHTML: contentRendered,contentCode,excerptRaw: excerpt,excerptHTML: excerptRendered,excerptCode,};return item;})

Get a post by its slug.

param
param

Functions

createBlog

  • createBlog(options?: Partial<BlogOptions>): { getAllPostsByDate: any; getPostBySlug: any }
  • Create a blog instance with the given options.

    Parameters

    Returns { getAllPostsByDate: any; getPostBySlug: any }

    blog instance

    • getAllPostsByDate: function
      • getAllPostsByDate(): Promise<Post[]>
    • getPostBySlug: function
      • getPostBySlug(slug: string): Promise<{ next: null | Post; post: Post; previous: null | Post }>

getAllPostsByDate

getNextPost

getPostSlugs

getPreviousPost

  • getPreviousPost(slug: string, options: BlogOptions): Promise<null | Post>

Object literals

Const defaultOptions

defaultOptions: object

Default options for your blog.

postsDirectory

postsDirectory: string = ""

The directory where your blog posts are stored.

truncateLength

truncateLength: number = 100

truncateMarker

truncateMarker: string = "<!--truncate-->"

mdx

mdx: object

components

components: {}

Type declaration

compile

  • compile(): Promise<never>

run

  • run(): Promise<never>

rewriteMediaUrls

rewriteMediaUrls: object

mediaDirectory

mediaDirectory: string = ""

The directory where your media files that are found in markdown should get copied to.

relativeDirectory

relativeDirectory: string = ""

The directory from which your media files should be served.

Generated using TypeDoc