octo
octo copied to clipboard
Import markdown files
As a user, I would like to upload my existing Markdown files to Octo. Markdown files will be parsed for metadata to determine whether they should create or update docs.
Related to #142
Hello is this still available for pickup?
@lyqht it is! Are you interested in working on it?
Hello @voracious, yes I'm keen to learn on how to contribute to this project, starting with this issue. May I ask
- what kind of metadata would it have to determine if a doc should be created or updated? (Examples are also ok if it's easier to show)
- are there any relevant files/code I should look at to speed up the dev process for this task?
Thanks!
@lyqht sure thing. To determine if a doc should be updated, it should meet the following criteria.
- Has an
id - Has a matching doc with the same
idin Octo - Has an
updated_atthat is more recent than the matching doc
Otherwise, create a new doc.
Supported metadata (frontmatter) fields
id: D2_xXXf-KpdnOjAslXbWE
created_at: 2022-09-04T23:04:29.863Z
discarded_at: 2022-09-04T23:04:29.863Z
updated_at: 2022-09-04T23:04:29.863Z
version: 0
Relevant areas of the codebase
In pages/docs/import.vue, there is a basic implementation of an importer that allows you to paste markdown to create a new doc, but it does not support updating an existing doc. This page should be a good starting point.
There are no links to the existing importer at the moment, but this should probably be added to the settings page near the link to the exporter.
You'll want to use the store to search, create, and update docs.
const [meta, text] = frontmatter(markdown) // extract the frontmatter and standalone text
if (meta.id) {
const existingDoc = this.$store.state.documents.all.find(doc => doc.id === meta.id)
if (existingDoc) {
// update the doc
return this.$store.commit(EDIT_DOCUMENT, {
id: existingDoc.id,
text,
})
}
}
return this.$store.commit(ADD_DOCUMENT, new Doc({ text }))
Happy to answer any other questions, but I hope this helps for now!
Hello @voracious, I started up the project locally and also tried to go to import.vue page, but it doesn't seem to create a doc at the moment (since you mentioned it should — just wanna clarify in case i'm missing something here).
I added an import button at the settings.vue as what you mentioned, maybe you can let me know if there's any preferred description later on.
Reading the code, I assumed that I can use an input from the exported markdown json so I tried that but I get unexpected end of JSON error
The same error happens even if i put a simple "Hello" string. Am I missing anything or is it part of my task to make create functional as well?
Thanks!
Hey @lyqht. That page is experimental, and I guess it was broken. 😅 I just pushed a fix for it, so hopefully it works for you now!