Problem with formatting (remote server only)

I got a problem. I am Russian speaker, so i have to write my blog post in Russian

Tested everything locally on MAMP (Kirby Starterkit and Brilliance theme) - everything went smooth. When i deployed it on Digital Ocean (Ubuntu 18.04, Apache 2.4, Php 7.2, installed only php-mbstring on top of that) - set all files permissions correctly. But all my blog posts written in Russian (on /blog page only) lost any king of markdown formatting and even excerpts (in fact, they have excerpts, but gigantic ones, like 2000 words). Meanwhile, it’s all nice and dandy on separate blog pages, with Markdown.

Save me, guys, i am so in love with Kirby <3

Could you post the code of the blog template, please?

The excerpt method removes all Markdown formatting, so I’m a bit surprised that the formatting is present locally? However, that doesn’t explain the long excerpts…

<?php snippet('header') ?>
<header class="wrap">
  <h1><?= $page->title()->html() ?></h1>

  // This page uses a separate controller to set variables, which can be used
  // within this template file. This results in less logic in your templates,
  // making them more readable. Learn more about controllers at:
  if($pagination->page() == 1):
    <div class="intro text">
      <?= $page->text()->kirbytext() ?>
  <?php endif ?>

  <hr />

<section class="wrap">
  <?php if($articles->count()): ?>
    <?php foreach($articles as $article): ?>

      <article class="article index">

        <header class="article-header">
          <h2 class="article-title">
            <a href="<?= $article->url() ?>"><?= $article->title()->html() ?></a>

          <p class="article-date"><?= $article->date('F jS, Y') ?></p>

        <?php snippet('coverimage', $article) ?>

        <div class="text">
            <?= $article->text()->kirbytext()->excerpt(50, 'words') ?>
            <a href="<?= $article->url() ?>" class="article-more">read more</a>


      <hr />

    <?php endforeach ?>
  <?php else: ?>
    <p>This blog does not contain any articles yet.</p>
  <?php endif ?>

<?php snippet('pagination') ?>
<?php snippet('footer') ?>

It’s just from the Starter Kit

And no, there’s no markdown formatting in these 50 words excerpts locally, but they are proper 50 words excerpts. Which is not the case when deployed remotely (they are massive chunks of unformatted mess)

Have you tried to set the locale with the language code for proper utf8 support

c::set('locale', 'ru_RU.utf8');

Before you do so, check what languages are installed on the server, to get the proper spelling here, sometimes it’s utf-8 or whatever.

Also, is the charset meta tag present and set to utf-8?

So, the problem is - it’s something wrong in my lab with these excerpts tag (or how you call it in PHP), and something wrong only when I do post in Russian. Obviously something wrong with my remote LAP stack, but I have no idea - what exactly? Recreated it with the same result on my prod Ubuntu 16.04 droplet where I have some PHP blog running (with dependcies only in mbsring, gd and MySQL, and I write there in Russian) for years without any hitch - and still no dice, same story. I am obviously missing something in PHP configuration in my stack, but what exactly?

I have no idea.Maybe you could use strrpos() instead of the excerpt function, as suggested here as a workaround: Excerpt word count : How does it work? ?

Did locale-gen and put what you said in config.php (am I doing it right?), still in vain.

Could you elaborate on charset meta, it’s all so unknown to me?

The charset meta tag is in the header snippet by default:

  <meta charset="utf-8">

But if everything else is OK, then this is rather not the problem but the excerpt function somehow not working as expected. Haven’t found anything yet on Google to help sort this out.

Maybe you can check for PHP differences between your local and remote setup (phpinfo()).

I did a quick test on my localhost. Without the locale setting in config.php, it just prints out the complete Russian text.

With locale set to

c::set('locale', 'ru_RU.UTF-8);

it works on my server, after I veryfied the exact locale with

locale -a

While the result is better than before, I still doesn’t give me exactly ten (or whatever you set) words. I think we would have to use mb functions here for this to work properly.

1 Like

If you can’t sort it out, maybe this helps:

// put the custom field method into a plugin file
field::$methods['toExcerpt'] = function($field, $words) {
    $string = $field->kt();
    $string = str_replace(PHP_EOL, ' ', trim($string));
    $array = mb_split('\s',$string);
    return implode(' ',array_splice($array,0,$words)).'…';
//in your template
echo $article->text()->toExcerpt(20);
1 Like