octo icon indicating copy to clipboard operation
octo copied to clipboard

Import markdown files

Open davidmyersdev opened this issue 4 years ago • 1 comments

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.

davidmyersdev avatar Oct 02 '21 02:10 davidmyersdev

Related to #142

davidmyersdev avatar Mar 01 '22 04:03 davidmyersdev

Hello is this still available for pickup?

lyqht avatar Oct 09 '22 03:10 lyqht

@lyqht it is! Are you interested in working on it?

davidmyersdev avatar Oct 09 '22 18:10 davidmyersdev

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 avatar Oct 10 '22 11:10 lyqht

@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 id in Octo
  • Has an updated_at that 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!

davidmyersdev avatar Oct 10 '22 14:10 davidmyersdev

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.

image

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

image

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!

lyqht avatar Oct 10 '22 20:10 lyqht

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!

davidmyersdev avatar Oct 11 '22 02:10 davidmyersdev