Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect postType media url and path #783

Open
22mahmoud opened this issue Jan 19, 2025 · 1 comment
Open

Respect postType media url and path #783

22mahmoud opened this issue Jan 19, 2025 · 1 comment

Comments

@22mahmoud
Copy link

Hey,

When trying to use indiekit to save the media files alongside the markdown itself , I'm encountering an error that indicates a photo type is required. Could you clarify the role of the media property in the postType configuration?
and here is my config

  publication: {
    me: "https://maw.sh",
    enrichPostData: true,
    postTemplate: getPostTemplate,
    postTypes: {
      note: {
        name: "Thoughts",
        post: {
          path: "src/thoughts/{t}/index.md",
          url: "/thoughts/{t}",
        },
        media: {
          path: "src/thoughts/{t}/{filename}",
          url: "/thoughts/{t}/{filename}",
        },
      },
      article: {
        name: "Blog",
        post: {
          path: "src/blog/{slug}/index.md",
          url: "/blog/{slug}",
        },
        media: {
          path: "src/blog/{slug}/{filename}",
          url: "/blog/{slug}/filename",
        },
      },
    },
  },
@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Jan 28, 2025

Hi @22mahmoud, thanks for trying Indiekit.

Indiekit guesses a post’s type from the properties that are provided in a Micropub request (be they sent either by a Micropub client or via Indiekit’s own post editing interface).

For example, a Note post type is a post containing content field; an Article post type is a post containing both name and content fields. If a post contains a photo field, it is inferred as having the Photo post type.

The media.path and media.url values tell Indiekit where to save media files to your content store for given post types. In most cases, these media values won’t make sense as many post types don’t include media by definition (i.e. Notes include short text snippets). The following post types can include media:

  • Photo
  • Video
  • Audio
  • any Article for which a content field is supplied (for example the article post type).

So, if you have a client that makes the following request to your Indiekit server:

multipart/form-data; boundary=553d9cee2030456a81931fb708ece92c

--553d9cee2030456a81931fb708ece92c
Content-Disposition: form-data; name="h"

entry
--553d9cee2030456a81931fb708ece92c
Content-Disposition: form-data; name="content"

Hello World!
--553d9cee2030456a81931fb708ece92c
Content-Disposition: form-data; name="photo"; filename="world.jpg"
Content-Type: image/png
Content-Transfer-Encoding: binary

... (binary data) ...
--553d9cee2030456a81931fb708ece92c--

Indiekit will infer this as being a Photo post (it has a photo property), so needs to know where to save the attached world.jpg image in your content store. It will look to postTypes.photo.media.path for this information.

Does this make sense? It’s all a bit complicated, so I’d welcome any feedback on how this could be better documented or explained.

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

No branches or pull requests

2 participants