splitting long article

User avatar
Jay
Master Bludit
Posts: 61
Joined: Mon Feb 11, 2019 8:41 pm

Fri Mar 22, 2019 9:44 pm

Does bludit have a builtin' solution to split long articles into paginated subpages ?
The only solution I could pretty fast implement bases on jquery, but I consider using jq as a last resort.
User avatar
SamBrishes
Sr. Bludit
Posts: 40
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Fri Mar 22, 2019 11:31 pm

Hellow,

I don't think so, at least the Page class itself doesn't provide such a functionallity. But theoretically you could create a plugin, which allows you to split your content into multiple pages. I quickly wrote the following example (It splits the content on the " <!--NextPage-->" comments, which you need to set on your own. The shown content is based on the "paged" _GET variable).

Code: Select all

class PaginationPlugin extends Plugin{
    public function beforeSiteLoad(){
        global $page;

        // Get Full Content
        $content = explode("<!--NextPage-->", $page->contentRaw());

        // Get shown Page
        $paged = 1;
        if(isset($_GET["paged"]) && $_GET["paged"] > 1){
            $paged = (int) $_GET["paged"];
        }
        if(count($content) < $paged){
            $paged = count($content);
        }

        // Render Content
        $content = $content[$paged-1];
        $parsedown = new Parsedown();
        $content = $parsedown->text($content);
        if(IMAGE_RELATIVE_TO_ABSOLUTE){
            $domain = IMAGE_RESTRICT?DOMAIN_UPLOADS_PAGES.$this->uuid().'/':DOMAIN_UPLOADS;
            $content = Text::imgRel2Abs($content, $domain);
        }
        $page->setField("content", $content);
    }
}
Sincerely,
Sam.
If you really like my projects and want to support me, I would be extremely grateful for a coffee! (Thanks to all Supporters):

Image
User avatar
Jay
Master Bludit
Posts: 61
Joined: Mon Feb 11, 2019 8:41 pm

Sat Mar 23, 2019 1:56 am

SamBrishes wrote:
Fri Mar 22, 2019 11:31 pm
I quickly wrote the following example
ohh, thanks for a fast response. I'm very positively surprised with example code you have provided. It works flawlessly! :)

Looks like I have now a tough nut to crack.
On the one hand it basically needs only to get article pagination, which I'll be working on, as your code is a solid base.
On the other hand such solution will need couple more things, like canonical URIs, friendly urls (always have problems with it), mobile detection and so on. Pretty much todo comparing to a "simple" jquery plugin ;)
User avatar
SamBrishes
Sr. Bludit
Posts: 40
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Sat Mar 23, 2019 4:28 pm

Hellow,

thanks, here you have:

GitHub - A Pagination Plugin 4 Bludit

The plugin has been written really quickly and I didn't test it very well (It worked on my local environment, which was fine for me :D). So I hope it works seamless, if not, give me a shout here or on GitHub.

It currently supports the following features:
  • En/Disable Pretty URLs
  • Configurable "paged" Variable
  • En/Disable a "Single-Page" View, using a special word as "paged" value
  • A Pager and a "Numeric" Pagination (+ a really basic design)
  • The Paginations can be hooked to "pageBegin" and "pageEnd"
  • Canonical URLs for the paged Pages
So I hope it is a better solution then using jQuery ;) .... PS.: What do you mean with a mobile detection? What should be handled differently on mobile devices?

Sincerely,
Sam.


Screenshots

Image

Image
If you really like my projects and want to support me, I would be extremely grateful for a coffee! (Thanks to all Supporters):

Image
User avatar
Jay
Master Bludit
Posts: 61
Joined: Mon Feb 11, 2019 8:41 pm

Sat Mar 23, 2019 8:51 pm

SamBrishes wrote:
Sat Mar 23, 2019 4:28 pm
The plugin has been written really quickly and I didn't test it very well (It worked on my local environment, which was fine for me :D). So I hope it works seamless, if not, give me a shout here or on GitHub.

It currently supports the following features:

[...]

So I hope it is a better solution then using jQuery ;) .... PS.: What do you mean with a mobile detection? What should be handled differently on mobile devices?
With your help I managed to get everything working with simple pagination like

Code: Select all

[prev page] Page 2 of 3 [next page]
and canonicals but .... wow, comparing my toy car to your optimus prime plugin makes me feel like I am still in woods :mrgreen:
For a "quickly" developed plugin, all implemented options are working very nice, and are SEO compliant - just as I intended to make :)

Last thing I wanted to implement, was a simpler way of inserting pagination marker, and I thought why not using the bludit's

Code: Select all

<!-- pagebreak -->
as bludit's editors have a button for it?

As for me, everything in your plugin works, and fullfills all ideas of article pagination. But of you would like, there's always place for improvements, and below couple things to consider beside using declared bludit's pagebreak option:

1.you implemented a single page option based on url parameter, which is configurable in plugin's options.
You could just add such button in "show pager" pagination mode on first page, so that it looks like:
[single page mode] Page 1 of 3 [next page]
Button could be optionally, and the text either configurable in options or sitting in json lang file.

2. when it goes to mobile thingy, I was going to check if browser's useragent contains any string related to mobile, and serve the user whole page anyway. It's related to the UX where those who browse on their phones are used to scrolling long websites. Of course assuming that the page doesn't contain half of Macbeth history.
But then I reminded myself that I used long time ago a pretty nice php class for mobile detection, which is still actively developed.
http://mobiledetect.net/

3.There could be a warning/notice message for those, who want to embed canonical urls in header, but have already enabled bludit's canonical plugin.

4. embedding .css could be an on/off option in additional settings.

Anyway great job!
Surely 100% better solution than making the website bloated with JQ ;)
User avatar
SamBrishes
Sr. Bludit
Posts: 40
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Sat Mar 23, 2019 11:45 pm

Hehe, thanks. I'm glad that you like it :D

I'm not sure, but I guess the <!-- pagebreak --> comment is primarly to separate the "Excerpt" (shown on the Homepage, for example) from the full content (shown on the page directly). But of course would it be possible to use that instead, preferred activatable about an own option.

(1.) An own button for the "Single-Page-Mode" is a good idea (2.) as well as the MobileDetect implementation. (3.) Maybe it is possible to "play" with Bludits canonical plugin, and change the behaviour in our favor (4.) and that is true!

I'll implement your ideas as soon as possible.

Thanks :D And yay as pure JS dev I'm glad about every jQuery-less solution. ^^

Sincerely,
Sam.
If you really like my projects and want to support me, I would be extremely grateful for a coffee! (Thanks to all Supporters):

Image
User avatar
Jay
Master Bludit
Posts: 61
Joined: Mon Feb 11, 2019 8:41 pm

Sun Mar 24, 2019 1:11 am

SamBrishes wrote:
Sat Mar 23, 2019 11:45 pm
I'm not sure, but I guess the <!-- pagebreak --> comment is primarly to separate the "Excerpt" (shown on the Homepage, for example) from the full content (shown on the page directly). But of course would it be possible to use that instead, preferred activatable about an own option.
I felt that all this pagebreak approach I had on mind is nothing new.
Now I remembered where from I got that. It's just that <pagebreak> marker is also used in Joomla (I had a long rendez vois with this cms). Not only for creating page excerpt, but also for paginating the article (joomla also offers additional headers for subpages along with ToC, but that's not the case).
And this is a good approach, as it doesn't need any additional syntax.
Not that the default pagebreak marker will change ... I hope so.

btw. the pros is that the excerpt might be used in two additional ways
1. it might be cut off in main article body, so it is used only in articles listings. Also the page metadesc field is filled with the beginning of the article.
2. it can be reused on every subpage as an article header.

Those are advanced options in managing paginated articles dedicated to big portals, and I have mixed feelings that a simple blog-like CMS would need them. But once I thought about using the same marker, I'd just check how would the paginated article look after implementing both options on a quite simple page. Just for a "dev's sake" ;)
User avatar
SamBrishes
Sr. Bludit
Posts: 40
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Thu Mar 28, 2019 10:09 pm

Hellow,

I'm not really into Joomla (just played a bit around with this CMS). But that's true an additional syntax should not be necessary for the most use-cases. And I don't think that the default pagebreak marker will change, but the user itself has still the opportunity to change it on his own (by editing the "PAGE_BREAK" syntax within the `variables.php` file).

BTW.: I started to collect all requested features on the GitHub repo. I hope I didn't forget something. :D

I guess also a simple blog-like CMS can and should be used for advanced websites. Partly it may is also better to use a small system, it's easier to learn and in the most cases also way easier to "extend" and "form" to the own needs. ;3

Sincerely,
Sam.
If you really like my projects and want to support me, I would be extremely grateful for a coffee! (Thanks to all Supporters):

Image
User avatar
SamBrishes
Sr. Bludit
Posts: 40
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Fri Apr 26, 2019 12:28 pm

Hellow,

sorry for the long wait. Finally, the Pagination plugin has been updated to version 0.2.0 and offers now a few more options and features.


Available on GitHub


Changelog
  • Add: The new german translation.
  • Add: A new option to change the used "nextpage" comment variable.
  • Add: A new option to prevent the plugin CSS file from loading.
  • Add: The canonical links doesn't get added, when the Canonical plugin is activated.
  • Add: The new option(s) to inject the pagination output at the start / end of the page' contents.
  • Update: The new default "nextpage" comment variable is Bludits "PAGE_BREAK" constant.
  • Update: All required Canonical links gets added, if the Canonical Plugin isn't activated.
  • Update: A new, improved admin UI, with some JavaScript functions.
  • Rename: The pagebegin_pagination option has been renamed into "pagination_top".
  • Rename: The pageend_pagination option has been renamed into "pagination_bottom".
  • Bugfix: Prevent content parsing on 404 Error pages.

Screenshot

Image

Sincerely,
Sam.
If you really like my projects and want to support me, I would be extremely grateful for a coffee! (Thanks to all Supporters):

Image
User avatar
Jay
Master Bludit
Posts: 61
Joined: Mon Feb 11, 2019 8:41 pm

Sun Apr 28, 2019 12:25 am

Works *great!
Not that initial v1.0 didn't ;)



*well, almost.
In initial release after I made a small change to use builtin bludit

Code: Select all

<!-- pagebreak -->
so that the first pagebreak occurence won't be counted.
Although devtheme has own excerpt creation function, the default bludit pagebreak code has its purpose.

I use this option only for convenience, as there's a button for it ;)
Post Reply