Skip to content

Conversation

@johannsa
Copy link
Contributor

@johannsa johannsa commented Mar 11, 2018

Without additional dependencies we can fix the issue of some non-ASCII characters disappearing from the slugs (replaced by separator) by using the more complete slug() function on Illuminate\Support\Str. The entire namespace Flarum\Util, containing only Flarum\Util\Str, would be redundant and is marked as deprecate.

Update: I have repurposed this PR to include my work on adding descriptions for the core and, on separate PR, for the flarum-ext-tags extension.

What do you think about this?

Copy link
Member

@luceos luceos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the deprecated Str class completely. We're in beta, we're allowed to make backward breaking changes 👍

Aside from this are you 100% sure you replaced all instances of our old Str class in the source?

Required follow up is refactoring extensions to stop using our Str class.

@johannsa
Copy link
Contributor Author

@luceos That's fine. I made dropped the class and with this the whole Flarum\Util namespace is also gone.

I confirm that before this PR I did a search and I cannot find any remaining usages of Flarum\Util\Str within the core or the bundled extensions. There were many usages of the Illuminate/Support/Str though.

@johannsa
Copy link
Contributor Author

Note: This may close #194
But I think eventually the separator and style of URL (https://discuss.flarum.org/d/187-word-association-game vs https://discuss.flarum.org/d/187) should be made configurable.

$this->attributes['title'] = $title;
$this->slug = Str::slug($title);
$app = Application::getInstance();
$locale = $app->make(LocaleManager::class)->getLocale() ?? 'en';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This locale depends on the currently active user. Shouldn't we always use either en or at least the board's default language here, so that we get consistent results?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think the default locale would make the most sense.

@johannsa johannsa changed the title Adding Laravel's slug generator function with transliteration Adding <meta> descriptions and Laravel's slug generator function with transliteration Apr 1, 2018
@johannsa
Copy link
Contributor Author

johannsa commented Apr 1, 2018

@franzliedke, @luceos The changes requested were made. Also, I am including the changes I was making to add description.

*/
protected function getDescriptionAttribute($description)
{
$description = ($description == null) ? $this->startPost->content : $description;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gonna be inefficient when listing discussions D:

Copy link
Contributor Author

@johannsa johannsa Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobscure Are you referring to $this->startPost->content, right? The other option is to always have a description (from discussion creation) on the database, not only when you (i.e.: via 3rd party extension) want to have a custom non-generated description there (that was my original intention when adding the field).

I guess we could:

  1. Store a generated (first 300 characters plus '...' if needed) description upon discussion creation and/or update.
  2. In case the forum admin is interested in custom descriptions a third party extension would have to set the description field and prevent it from being edited (via additional listeners and maybe additional field) in case the OP edits the start post.

What do you think about this approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we need to do something like this - any better ideas @franzliedke?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line we're talking about could also have been improved with the null coalescence operator.

I, however, agree to store a generated description, but only if none is set beforehand.

@johannsa
Copy link
Contributor Author

johannsa commented Apr 2, 2018

Tasks

  • Uncommit the dist files.
  • Make Flarum to store a generated (first 300 characters plus '...' if needed) description upon discussion creation and/or update.
  • Make the migration to generate (and store) description for existing discussions.

@franzliedke
Copy link
Contributor

@johannsa Are you still interested in finishing this? We'd highly appreciate it. 😃

@tobyzerner
Copy link
Contributor

tobyzerner commented Sep 15, 2018

@johannsa If you're interested in finishing this, it would be amazing if you could extract the slug generation changes into a separate PR so we could get that part merged in soon! Otherwise I will close this.

@stale
Copy link

stale bot commented Jan 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum.
In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!

@stale stale bot added the stale Issues that have had over 90 days of inactivity label Jan 18, 2020
@franzliedke
Copy link
Contributor

I extracted the switch to Laravel's slugger (that has basic transliteration support) into a new PR - #1975.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Issues that have had over 90 days of inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants