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

Customised slugs for posts #2916

Open
abhas opened this issue Mar 22, 2021 · 5 comments
Open

Customised slugs for posts #2916

abhas opened this issue Mar 22, 2021 · 5 comments

Comments

@abhas
Copy link

abhas commented Mar 22, 2021

Is your feature request related to a problem? Please describe.

While reposting something or creating a bookmark, I don't seem to have any control on the generated slug. For bookmarks, for example, the slug is derived from the title of the bookmark.

Describe the solution you'd like

I has hoping for a way to to either customise the slug manually. Or use random, numeric, non-sequential slugs so that the URL shorter and also more meaningful.

If there is a quick hack to do this at the backend, I would be glad to experiment and report back.

@lindner
Copy link
Collaborator

lindner commented Mar 22, 2021 via email

@abhas
Copy link
Author

abhas commented Mar 22, 2021

I think this is supported in the micropub endpoint, so it's just a matter of exposing that in the posting interface.
A workaround is to use something like https://quill.p3k.io to post which allows you to customize the slug.

Thank you. That's a great suggestion. Quill lets you set custom slugs for new posts. Unfortunately, likes, reposts and bookmarks still have very long permalink URLs. Let me try out other micropub tools and see if any of them might be more suitable.

@abhas
Copy link
Author

abhas commented Mar 22, 2021

So while Micropublish allows one to customise the slugs, Known does not respect them. Both Quill and Micropublish use the "mp-slug" as the attribute to store the slug. I couldn't find a mention of this in the Known code. Perhaps the attribute that needs to be sent is different.

@abhas
Copy link
Author

abhas commented Mar 22, 2021

I added this line:

$slug = date("mds");

just before this line here Idno/Common/Entity.php#L841 and now my permalinks are in the /:year/mds format. Eg. 2021/032241. That works well for me now since the links are always going to be unique and a fixed length (as long as I don't bookmark twice within the same second!).

Now it also doesn't matter if I use Known's built in bookmarklet or Quill or Micropublish.

@kkd
Copy link

kkd commented Apr 4, 2021

@abhas this issue is related to idno/indiepub#9.

I hacked customized slugs on my site to add 'mp-slug' in IndiePub plugin.
But I use Japanese, so I prefer to generate slug from date time automatically ;-)

diff --git a/Pages/MicroPub/Endpoint.php b/Pages/MicroPub/Endpoint.php
index 6ae9221..38c8106 100644
--- a/Pages/MicroPub/Endpoint.php
+++ b/Pages/MicroPub/Endpoint.php
@@ -169,6 +169,7 @@ namespace IdnoPlugins\IndiePub\Pages\MicroPub {
                 $video_url   = $this->getJSONInput('video');
                 $audio_url   = $this->getJSONInput('audio');
                 $visibility  = $this->getJSONInput('visibility');
+                $slug        = $this->getJSONInput('mp-slug');
 
                 // Handle visibility
                 if(is_array($visibility) && array_key_exists(0, $visibility)) {
@@ -249,7 +250,8 @@ namespace IdnoPlugins\IndiePub\Pages\MicroPub {
                 $photo_url   = $this->getInput('photo');
                 $video_url   = $this->getInput('video');
                 $audio_url   = $this->getInput('audio');
-                $visibility   = $this->getInput('visibility');
+                $visibility  = $this->getInput('visibility');
+                $slug        = $this->getInput('mp-slug');
             }
 
             if (!empty($mp_type)) {
@@ -440,6 +442,11 @@ namespace IdnoPlugins\IndiePub\Pages\MicroPub {
                         \Idno\Core\Idno::site()->logging()->info("Setting syndication: $syndication");
                         $this->setInput('syndication', $syndication);
                     }
+
+                    if (!empty($slug)) {
+                        $entity->setSlug($slug);
+                    }
+
                     if ($entity->saveDataFromInput()) {
                         \Idno\Core\Idno::site()->events()->triggerEvent('indiepub/post/success', ['page' => $this, 'object' => $entity]);
                         $this->setResponse(201);

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

3 participants