Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions bin/commands/generate/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { getBlogPath, getBlogTemplatePath } from '../../utils/content'
import { getBlogPath, getBlogTemplatePath, getPackages, loadBlogContent, loadPackageContent } from '../../utils/content'
import { slugify } from '../../utils/slugify'
import { getBlogImagesPath } from '../../utils/public'

Expand Down Expand Up @@ -36,7 +36,33 @@ export const content = defineCommand({
const blogTemplatePath = getBlogTemplatePath()
const template = readFileSync(blogTemplatePath, 'utf-8')

const content = template.replace('blog_title', title).replaceAll('blog_date', date)
const addCategories = await consola.prompt('Do you want to add categories to the article?', {
type: 'confirm',
})
const categoriesToAdd: string[] = []
if (addCategories)
consola.log(loadBlogContent('super'))

// categoriesToAdd.push(...selecT)

// Ask for packages to include
const addPackages = await consola.prompt('Do you want to include packages in the article?', {
type: 'confirm',
})
const packagesToAdd: string[] = []
if (addPackages) {
const packages = getPackages()
const packagesContent = packages.map(p => loadPackageContent(p))

const selectedPackages = await consola.prompt('Select packages to include in the article', {
type: 'multiselect',
options: packagesContent.map(p => p.title),
})

packagesToAdd.push(...selectedPackages)
}

const content = template.replace('blog_title', title).replaceAll('blog_date', date).replace('blog_packages', packagesToAdd.join('\n - ')).replace('blog_categories', categoriesToAdd.join('\n - '))
const path = join(blogPath, filename)
writeContent(content, path)

Expand Down
17 changes: 17 additions & 0 deletions bin/utils/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from 'node:path'
import { cwd } from 'node:process'
import yaml from 'js-yaml'
import { ofetch } from 'ofetch'
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
import type { ContentPackage, GitHubFile } from '../types'

export function getContentPath() {
Expand Down Expand Up @@ -70,3 +71,19 @@ export async function getExamplesLink(name: string) {

return hasExamples ? `https://github.com/unjs/${name}/blob/main/examples` : null
}

export function loadBlogContent(name: string) {
return parseMarkdown(readFileSync(join(getBlogPath(), name), 'utf-8'))
}

/**
* Create a function that load every blog file
* Create a function that load a md file, parse front-matter
* Create a function that get, from every articles, categories
* Repeat for authors
*
* Add a command to view all authors
* Add a command to view all categories
*
* (split in many files)
*/
4 changes: 2 additions & 2 deletions content/blog/.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ authors:
picture:
twitter:
categories:
-
- blog_categories
packages:
-
- blog_packages
publishedAt: blog_date
modifiedAt: blog_date
---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@iconify-json/ph": "^1.1.11",
"@iconify-json/simple-icons": "^1.1.90",
"@iconify-json/vscode-icons": "^1.1.33",
"@nuxt/content": "^2.10.0",
"@nuxt/content": "^2.12.0",
"@nuxt/ui": "^2.12.0",
"@nuxtjs/fontaine": "^0.4.1",
"@nuxtjs/google-fonts": "^3.1.3",
Expand Down
Loading