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

Micropub channels #774

Merged
merged 5 commits into from
Nov 17, 2024
Merged

Micropub channels #774

merged 5 commits into from
Nov 17, 2024

Conversation

paulrobertlloyd
Copy link
Collaborator

@paulrobertlloyd paulrobertlloyd commented Nov 16, 2024

Adds support for the channels extension in Micropub requests. Fixes #773.

This can be used to dictate where a post gets published within a publication, and potentially allows for posts of the same type to be published to different locations.

Adds:

  • New publication.channels configuration option
  • Querying /micropub?q=config includes a channels property with configured channels
  • Querying /micropub?q=channel returns configured channels

If channels are configured:

  • The default channel is the first value given for publication.channels
  • If a request includes an mp-channel value, it gets saved to properties.channel
  • If a request doesn’t include mp-channel, the default channel UID is used
  • If a request includes values for mp-channel that don’t exist in publication.channels, they’ll get ignored. If no values match, the default channel UID is used
  • Post form shows a ‘Channels’ field under ‘Advanced options’, with checkboxes to select for each of the configured channels
  • Post page shows channels specified for a given post
  • A {channel} token is available to use in paths; if multiple channels are assigned to a post, these will get separated using the slug separator character

Screenshot of channels in advanced options on post form.

Example

In publication config:

publication: {
  channels: {
    en: {
      name: "English"
    },
    de: {
      name: "German"
    }
  },
  postTypes: {
    article: {
      post: {
        path: "_posts/{channel}/{yyyy}-{MM}-{dd}-{slug}.md",
        url: "{channel}/{yyyy}/{MM}/{slug}"
      }
    }
  }
}
GET /micropub?q=channel

"channels": [
  {
    "uid": "en",
    "name": "English"
  },
  {
    "uid": "de",
    "name": "German"
  }
]

Published to /en/2024/11/channels:

POST /micropub
Content-Type: application/json

{
  "type": "h-entry",
  "properties" {
    "mp-channel": "en",
    "name": "Channels",
    "content": "Hello, world."
  }
}

Published to /de/2024/11/kanale:

POST /micropub
Content-Type: application/json

{
  "type": "h-entry",
  "properties" {
    "mp-channel": "de",
    "name": "Kanäle",
    "content": "Hallo Welt."
  }
}

How should this value be used by presets?

Right now, if a publication has channels configured, the default (or chosen) channel(s) will get saved to properties.channel, so for example a post might look like this:

----
published: 2024-11-16
title: Channels
channel:
  - en
----
Hello, world.

I think channels are analogous to Eleventy collections, so potentially for that preset, the channel property should be used for tags? But you might want to use properties.category for the tags field instead. Not sure what is the right approach, but can figure that out in a separate PR.

Might this value have equivalent representations in other platforms, too?

Should a default channel be enforced?

Right now, a default channel is enforced. That means, while you might only want to use the channel property for the output path, the channel property would still get added to frontmatter properties as well. Maybe that’s fine (though this’d make be twinge…)

@paulrobertlloyd paulrobertlloyd added enhancement New feature or request plugin-endpoint Endpoint plug-in core Core indiekit package labels Nov 16, 2024
@paulrobertlloyd paulrobertlloyd added this to the v1.0 milestone Nov 16, 2024
@paulrobertlloyd
Copy link
Collaborator Author

@benjaminparry This might solve the issue you’ve got with wanting to post articles to 2 different locations on your website.

@gerwitz You had previously asked about having more ways to organise posts; would this help?

@gerwitz
Copy link

gerwitz commented Nov 16, 2024

Indeed, this is perfect for my case

@paulrobertlloyd
Copy link
Collaborator Author

@gerwitz Out of interest, how would you use this feature (do you use 11ty)? Is it a problem that a default channel is always set if no channels are provided?

@paulrobertlloyd paulrobertlloyd merged commit e4a9623 into main Nov 17, 2024
1 of 2 checks passed
@paulrobertlloyd paulrobertlloyd deleted the feat/773-channels branch November 17, 2024 18:23
@benjaminparry
Copy link
Contributor

Well that escalated quickly! I’ll find some time to catch up this week. Thanks Paul!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core indiekit package enhancement New feature or request plugin-endpoint Endpoint plug-in
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Channels
3 participants