Add way to set page preview content #907

Open
opened 2026-02-04 22:52:23 +03:00 by OVERLORD · 16 comments
Owner

Originally created by @derek-shnosh on GitHub (Nov 16, 2018).

Describe the feature you'd like
Allow the page Subtitle to be specified on the page.

Example;

<!-- SUBTITLE: Document Subtitle, Meta Description -->

Describe the benefits this feature would bring to BookStack users
Instead of giving the first n characters of the document on the chapter screen, we can specify a subtitle.

Additional context

Current image
Subtitled image
Originally created by @derek-shnosh on GitHub (Nov 16, 2018). **Describe the feature you'd like** Allow the page Subtitle to be specified on the page. _Example;_ ``` <!-- SUBTITLE: Document Subtitle, Meta Description --> ``` **Describe the benefits this feature would bring to BookStack users** Instead of giving the first _n_ characters of the document on the chapter screen, we can specify a subtitle. **Additional context** | Current | ![image](https://user-images.githubusercontent.com/21090563/48600689-d0bc6400-e921-11e8-9343-4edc0db56795.png) | | :-: | :-: | | Subtitled | ![image](https://user-images.githubusercontent.com/21090563/48600856-87b8df80-e922-11e8-9a52-a8fcb4f18c5f.png) |
OVERLORD added the 🛠️ Enhancement🔨 Feature Request labels 2026-02-04 22:52:23 +03:00
Author
Owner

@heroin-moose commented on GitHub (Nov 29, 2018):

+1

Would be very helpful.

@heroin-moose commented on GitHub (Nov 29, 2018): +1 Would be very helpful.
Author
Owner

@heroin-moose commented on GitHub (Nov 29, 2018):

But not only in markdown, I guess.

@heroin-moose commented on GitHub (Nov 29, 2018): But not only in markdown, I guess.
Author
Owner

@ezzra commented on GitHub (Dec 10, 2018):

I would propose to add an extra field for this subtitle/summary, I just added an issue before I found this existing #1169

@ezzra commented on GitHub (Dec 10, 2018): I would propose to add an extra field for this subtitle/summary, I just added an issue before I found this existing #1169
Author
Owner

@ssddanbrown commented on GitHub (Dec 10, 2018):

I've updated the title of this issue to not focus on a single editor in the interest in keeping them feature aligned.

Too add my thoughts, Personally I feel this would be a very micromanage-ery level feature. Within the editor it would have to be very out-of-the way (In the sidebar like tags) but then that does reduce visibility and opens up things like risk of custom-set preview text not being updated.

@ssddanbrown commented on GitHub (Dec 10, 2018): I've updated the title of this issue to not focus on a single editor in the interest in keeping them feature aligned. Too add my thoughts, Personally I feel this would be a very micromanage-ery level feature. Within the editor it would have to be very out-of-the way (In the sidebar like tags) but then that does reduce visibility and opens up things like risk of custom-set preview text not being updated.
Author
Owner

@heroin-moose commented on GitHub (Dec 10, 2018):

Actually @ezzra is right, it should be done via an extra field.

@heroin-moose commented on GitHub (Dec 10, 2018): Actually @ezzra is right, it should be done via an extra field.
Author
Owner

@ezzra commented on GitHub (Dec 10, 2018):

I wouldn't put it somewhere out of sight, I also have a problem with the tags and attachments being more or less completely out of sight, but thats another topic. I could imagine something like "add a subtitle" button that displays a second field beneath the title field. But of course with smaller font etc.

That would also go along with actually using it also as a subtitle beneath the title (sic!) in the page view.

@ezzra commented on GitHub (Dec 10, 2018): I wouldn't put it somewhere out of sight, I also have a problem with the tags and attachments being more or less completely out of sight, but thats another topic. I could imagine something like "add a subtitle" button that displays a second field beneath the title field. But of course with smaller font etc. That would also go along with actually using it also as a subtitle beneath the title (sic!) in the page view.
Author
Owner

@takazerker commented on GitHub (Feb 10, 2021):

+1

As a temporary solution, I changed Entity.php to display only first line.

public function getExcerpt(int $length = 100): string
{
    $text = $this->getText();

    // Display only first line
    if ($length > 0) {
        $text = explode($text, '\n', 2)[0];
    }
@takazerker commented on GitHub (Feb 10, 2021): +1 As a temporary solution, I changed Entity.php to display only first line. ``` public function getExcerpt(int $length = 100): string { $text = $this->getText(); // Display only first line if ($length > 0) { $text = explode($text, '\n', 2)[0]; } ```
Author
Owner

@stijink commented on GitHub (Jun 21, 2022):

+1

@stijink commented on GitHub (Jun 21, 2022): +1
Author
Owner

@Semetra22 commented on GitHub (Oct 11, 2022):

+1

@Semetra22 commented on GitHub (Oct 11, 2022): +1
Author
Owner

@gaufde commented on GitHub (Jan 20, 2023):

Too add my thoughts, Personally I feel this would be a very micromanage-ery level feature. Within the editor it would have to be very out-of-the way (In the sidebar like tags) but then that does reduce visibility and opens up things like risk of custom-set preview text not being updated.

I think that this would be a good way to add this feature! I personally don't mind it being somewhat hidden in the UI. I also think this feature would be a good addition to Bookstack, so +1.

@gaufde commented on GitHub (Jan 20, 2023): > Too add my thoughts, Personally I feel this would be a very micromanage-ery level feature. Within the editor it would have to be very out-of-the way (In the sidebar like tags) but then that does reduce visibility and opens up things like risk of custom-set preview text not being updated. I think that this would be a good way to add this feature! I personally don't mind it being somewhat hidden in the UI. I also think this feature would be a good addition to Bookstack, so +1.
Author
Owner

@Djones4822 commented on GitHub (May 15, 2023):

+1 would very much like this feature

@Djones4822 commented on GitHub (May 15, 2023): +1 would very much like this feature
Author
Owner

@Djones4822 commented on GitHub (May 24, 2023):

public function getExcerpt(int $length = 100): string
{
    $text = $this->getText();

    // Display only first line
    if ($length > 0) {
        $text = explode($text, '\n', 2)[0];
    }

Your parameters for explode are reversed, prior to php8 i guess you might not have noticed this but now there are cases where this will throw an error. Also, you can't use single quotes or the \n won't be parsed. Lastly, if your page begins with a new line (dunno why) then it would use a blank description. I did not want that last behavior. This is now working for me:

    /**
     * Get an excerpt of this entity's descriptive content to the specified length.
     */
    public function getExcerpt(int $length = 100): string
    {
        $text = $this->{$this->textField} ?? '';

        // Trim to first non-empty line
        if ($length > 0) {
            $texts = explode("\n", $text);
            foreach ( $texts as $t){
                if(!empty(trim($t))){
                    $text = $t;
                    break;
                }
            }
        }

        if (mb_strlen($text) > $length) {
            $text = mb_substr($text, 0, $length - 3) . '...';
        }

        return trim($text);
    }

To achieve a description that isn't on the page, you can write the text you want, and then edit the page source and add style="display: None" to your description section. This will hide the text from displaying but the text will still be used as the description. To edit the "description" later, you will need to edit it via the source code since the editor won't show it anymore.

Just to note: This change does not appear to affect Shelf, Book, and Chapter descriptions which do not have their descriptions fetched via the getExcerpt() method.

@Djones4822 commented on GitHub (May 24, 2023): > ```php >public function getExcerpt(int $length = 100): string > { > $text = $this->getText(); > > // Display only first line > if ($length > 0) { > $text = explode($text, '\n', 2)[0]; > } > ``` Your parameters for explode are reversed, prior to php8 i guess you might not have noticed this but now there are cases where this will throw an error. Also, you can't use single quotes or the \n won't be parsed. Lastly, if your page begins with a new line (dunno why) then it would use a blank description. I did not want that last behavior. This is now working for me: ```php /** * Get an excerpt of this entity's descriptive content to the specified length. */ public function getExcerpt(int $length = 100): string { $text = $this->{$this->textField} ?? ''; // Trim to first non-empty line if ($length > 0) { $texts = explode("\n", $text); foreach ( $texts as $t){ if(!empty(trim($t))){ $text = $t; break; } } } if (mb_strlen($text) > $length) { $text = mb_substr($text, 0, $length - 3) . '...'; } return trim($text); } ``` To achieve a description that isn't on the page, you can write the text you want, and then edit the page source and add `style="display: None"` to your description section. This will hide the text from displaying but the text will still be used as the description. To edit the "description" later, you will need to edit it via the source code since the editor won't show it anymore. Just to note: This change does not appear to affect Shelf, Book, and Chapter descriptions which do not have their descriptions fetched via the getExcerpt() method.
Author
Owner

@ZOXSOCKS commented on GitHub (Sep 11, 2024):

+1

@ZOXSOCKS commented on GitHub (Sep 11, 2024): +1
Author
Owner

@Kornosky commented on GitHub (May 20, 2025):

+1

@Kornosky commented on GitHub (May 20, 2025): +1
Author
Owner

@joshhcd commented on GitHub (May 29, 2025):

+1

@joshhcd commented on GitHub (May 29, 2025): +1
Author
Owner

@lannieligthart commented on GitHub (Nov 28, 2025):

+1

@lannieligthart commented on GitHub (Nov 28, 2025): +1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#907