docpad/docpad-plugin-paged

Issue with live reloading / cleanurls

Closed this issue · 7 comments

Hi, there seems to be a bug when making a change to the document with live-reload / cleanurls

The scenario is this; lets say I have a paginated file at news.html which gets split to
news.html and news.1.html.

cleanurls are active so the urls would be mysite.com/news and mysite.com/news.1

The links for next and previous page on both pages direct to correct pages.

I now make a change to a css file or markdown file or something that will cause news.html to be regenerated.

After the next cycle of writing/regenerating. I attempt to go news.1, but it instead redirects to news. The link on news.html says in the source that it points to news.1.html, but clinking on the link sends me to news.html.

Running docpad in debug mode, I have noticed that on first run it will render and write out news.1.html. Upon making a change, it renders the page but does not proceed to write it out.

Not quite sure what it is going on.

Thanks for the report Matt.

I just did a quick test and you're absolutely right there's something weird going on. This plugin is proving quite the headache, works fine for static page generation with cleanurls, and dynamic generation without cleanurls.

I will have to dig into this some more, but I probably won't get a chance for a couple of weeks. Feel free to attempt a fix yourself and file a pull request if you're successful.

Letting you know I'm still working to resolve this.

I have noticed that on first-run, docpad correctly adds the paged files to the database, However, for whatever reason upon reloading the paged files are no longer in the database; this is despite the call to add the document to the database in the callback that is present in the renderAfter event of the plugin.

I shall continue snooping.

Ugh. I've updated docpad and all my plugins to see if something upstream resolves the issue. It does; sort of. I've noted on a reload it's remapping an item in my navbar to it's latest paged version (ie news.1 when it should be news). The issue with it mapping a url from news.1 to news has been resolved though. I have noticed that live-reload won't fire the paged plugin if for say, you update a singular post. Updating paged document that holds those post will. Will try to investigate further.

Found a hack you can do to the docpad source code to get around this.

If you can go into the docpad.js file and change the performGenerate function so that opts.reset ?= true instead of false, it will force live reload to do a full reset every time a page is updated; this prevents the issue. Still looking for a better fix though.

Good work matt.

I've not had a chance to get back into this yet, I might have to exchange some emails with @balupton to see if we can figure out a more stable way to approach this plugin.

Having a bit of a look into the problem here, and I think part of it can be easily fixed, in this blog you have this:

if (firstPageUrl=='/')
    newUrl = '/index.' + pageNumber + '.html'
else
    newUrl = firstPageUrl.replace(/\.html/,'.'+pageNumber+'.html')

cleanUrls = docpad.getPlugin('cleanurls')
if (cleanUrls)
    newUrl = newUrl.replace(/\.html$/, '');

The assumption being made is that the URL will always have an extension, but in my setup it's not been the case, instead you could write this:

if (firstPageUrl=='/')
    newUrl = '/index'
else
    newUrl = firstPageUrl.replace(/\.html/,'')

newUrl += '.' + pageNumber

cleanUrls = docpad.getPlugin('cleanurls')
if (!cleanUrls)
    newUrl += '.html'

This way you change the assumption to be the other way around, assume extensionless URLs and append one if required.

I was going to send a PR but I have another problem (which I'm not sure if it's my implementation or not) where the paged pages are always 404'ing (but I have a hack to fix that one 😛).

Please try out DocPad v6.44 with Paged v2.2 as there has been huge improvements in this area. Happy to re-open if it is still an issue.