Skip to content

Conversation

@Rotten-LKZ
Copy link

@Rotten-LKZ Rotten-LKZ commented Apr 15, 2023

I have added a feature to the extension which you can add post by clicking the bottom 'Add a Post' on the navigator. It works like this:
image
image
image

@Rotten-LKZ
Copy link
Author

src/view/ValaxyProvider.ts

// ...
await workspace.fs.writeFile(filePath, Buffer.from(`---
title: 
date: ${now}
updated: ${now}
tags:
  - 
categories: 
---\n`))
// ...

However, I'm not sure where to put these lines of code for the template of the new posts, and I feel like it would be abrupt if I just put them in directly.

@YunYouJun
Copy link
Member

Thanks for your contribution, this is exactly the kind of feature I want to add later!

Regarding the issue you mentioned, I think we should put it in the res/md folder, and first check if the post.md file exists under the user scaffolds/ folder, if it does, we can use the user-defined template first.

@Rotten-LKZ
Copy link
Author

The basic functionality has been implemented, but I feel that the logic in my code is not very clear. I hope YunYouJun can provide some guidance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async add(): Promise<void> {
const EXIST_NOTICE_MSG = 'A post with the same name already exists'

const input1 = await window.showInputBox({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a clearer name: postName

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to use trim()

return

try {
await workspace.fs.stat(Uri.joinPath(uri, '/scaffolds', `${input1}.md`))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is post.md, I think we should use it directly, and only need one input for postName.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or a select (query option form scaffolds)

@YunYouJun
Copy link
Member

Is there any progress?

const second = date.getSeconds()

const pad = (n: number) => n.toString().padStart(2, '0')
return `${year}-${pad(month)}-${pad(day)} ${pad(hour)}:${pad(minute)}:${pad(second)}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use dayjs to format it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants