Coder Social home page Coder Social logo

silverstripe-staticpublisher's Introduction

StaticPublisher

Build Status

This module is unmaintained, please use silverstripe/staticpublishqueue instead

Introduction

This module provides an extension for exporting a SilverStripe application as static files to both a local or remote server for increased site performance.

Maintainer Contact

* Will Rossiter (Nickname: wrossiter, willr) `<[email protected]>`
* Sam Minneé (Nickname: sminnee) <[email protected]>

Requirements

  • SilverStripe 3.1 or newer
  • Tar archive

Documentation

See the docs folder.

Note this is untested on Windows.

silverstripe-staticpublisher's People

Contributors

adamjudd avatar chillu avatar christopherdarling avatar dhensby avatar ec8or avatar halkyon avatar kevcenteno avatar mateusz avatar nedmas avatar simonwelsh avatar ss23 avatar threesquared avatar wilr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silverstripe-staticpublisher's Issues

Cache sites using https instead of http

Our site is reachable through http and https. When a site gets cached, there should be two cached versions of it, namely http and https.

If that would not be possible, that the static publisher should at least cache the https version, so when visiting via https, all media gets displayed.

Is there a way to archeive this? I couldn't find out so far.

Bug: StaticPublisher::republish() doesn't strip slashes from $legalPages

If pagesAffectedByChanges() end allPagesToCache() both return urls with a trailing slash, then StaticPublisher::republish() wil strip that slash from its $urls, but not from its $legalPages. So intersecting $urls and $legalPages will allways return an empty array.

This afflicts master and v1.1.0

Solution: strip the slashes from $legalPages as well.

Temporary workaround: make sure your pagesAffectedByChanges() end allPagesToCache() return $urls without trailing slash :)

Method 'getMetadata' doesn't exist on StaticPublisher

When StaticPublisher.include_caching_metadata is set to true the method 'getMetadata' is executed but it doesn't exist. What is this method intended to do? At the moment the result of this method is just expected to be add as a comment to the bottom of the cached file?

Actually not working with SS 3.1.0-rc1

Redirecting dynamic traffic through staticpublisher/main.php does not permit access to admin/ LoginForm/ error-pages etcetera.

Maybe it's just an .htaccess issue, but I think that some code manipulation is required.

Here you are my .htaccess rules:

    RewriteEngine On

    ## CONFIG FOR TEST/LIVE ENVIRONMENTS

    # Cached content - live webserver
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} /(.*[^/])/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/index.html [L]

    ## DYNAMIC CONFIG

    # Dynamic content
    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
#   RewriteCond %{REQUEST_URI} !/admin.*$
#   RewriteCond %{REQUEST_URI} !/Security/login.*$
#   RewriteCond %{REQUEST_URI} !/Security/LoginForm.*$
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* staticpublisher/main.php?url=%1&%{QUERY_STRING} [L]

Update minimum requirement to 3.2, classes are still in 3.1 core

Did we mess up a pull request from you there, Will? I can't find any
which should've removed those classes from core, they're still present:

https://github.com/silverstripe/silverstripe-cms/tree/master/code/staticpublisher
https://github.com/silverstripe/silverstripe-cms/tree/3.1/code/staticpublisher

Could you port over any changes made to those classes since you created the module,
and submit a pull request against master which removes them, and notes that in docs/en/changelogs/3.2.0.md?

Thanks!

Notice: Use of undefined constant BASE_URL

I was getting errors on my local install that has reporting turned up and thought I would share a fix for this notice.

Adding the line below here removes the notice.

require_once('../framework/core/Constants.php');

Which has been taken from SilverStripes framework main.php

I am fairly new to SilverStripe and am not sure if this omission was on purpose and what the implications of adding this in.

Convert class not available when hitting cached PHP files

Not sure if this is an issue with SSViewer or Static Publisher, but we're running into an issue when we have a list of hash links on a page that we're trying to statically publish to cache/faq.php.

When statically publishing the page, I notice that the rewrite_hash_links setting is set to "php" which causes SSViewer to generate this URL (from SSViewer.php):

<?php echo Convert::raw2att(preg_replace(\"/^(\\\\/)+/\", \"/\", \$_SERVER['REQUEST_URI'])); ?>"

But since we're not hitting SilverStripe's class manifest, then we can't use the "Convert" object and rendering faq.php fails.

method 'setsession' does not exist on 'RebuildStaticCacheTask'

Have setup _config.php (SS3.1)

SiteTree::add_extension("FilesystemPublisher('cache/')");
Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");

Have added functions to top of Page.php (not to Page_Controller)

    /**
     * Return a list of all the pages to cache
     *
     * @return array
     */
    public function allPagesToCache() {
        // Get each page type to define its sub-urls
        $urls = array();

        // memory intensive depending on number of pages
        $pages = SiteTree::get()->where("ClassName != 'UserDefinedForm'");

        foreach($pages as $page) {
            $urls = array_merge($urls, (array)$page->subPagesToCache());
        }

        // add any custom URLs which are not SiteTree instances
        $urls[] = "sitemap.xml";

        return $urls;
    }

    /**
     * Get a list of URLs to cache related to this page.
     *
     * @return array
     */
    public function subPagesToCache() {
        $urls = array();

        // add current page
        $urls[] = $this->Link();

        // cache the RSS feed if comments are enabled
        if ($this->ProvideComments) {
            $urls[] = Director::absoluteBaseURL() . "CommentingController/rss/SiteTree/" . $this->ID;
        }

        return $urls;
    }

    /**
     * Get a list of URL's to publish when this page changes
     */
    public function pagesAffectedByChanges() {
        $urls = $this->subPagesToCache();
        if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
        return $urls;
    }

Next, when running http://localhost:8888/website/dev/buildcache I receive the following error:

[User Error] Uncaught Exception: Object->__call(): the method 'setsession' does not exist on 'RebuildStaticCacheTask'
GET /website/dev/buildcache
Line 750 in /Users/MyName/Sites/website/framework/core/Object.php
Source
741 default :
742 throw new Exception (
743 "Object->__call(): extra method $method is invalid on $this->class:"
744 . var_export($config, true)
745 );
746 }
747 } else {
748 // Please do not change the exception code number below.
749 $class = get_class($this);
750 throw new Exception("Object->__call(): the method '$method' does not exist on '$class'", 2175);
751 }
752 }
753
754 // --------------------------------------------------------------------------------------------------------------
755
756 /**
Trace
Object->__call(setSession,Array)
Director.php:322
RebuildStaticCacheTask->setSession(Session)
Director.php:322
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:143
Director::direct(/dev/buildcache,DataModel)
main.php:189

Legacy URL tool

From http://open.silverstripe.org/ticket/1993

It would be good to have a system for dealing with Legacy URLs in the CMS.

Perhaps each page in the CMS can have a Legacy URL field. If that URL is visited, the user would be permanently redirected to the new page.

If we implemented the "optional director rule" system for multi-lingual sites - having a director rule that is applied only in some circumstances - we could use that to implement a LegacyURLController that was checked for every URL, but only executed if the URL passed matched something in the LegacyURL column of SiteTree?.

This could be implemented as an add-on module quite easily - a decorator on SiteTree? and an extra, high priority director rule.

@sminnee

RsyncMultiHostPublisher::config() - PHP Fatal

Hey,
I've got a 3.1.3 standard install with silverstripe-staticpublisher as the first module included, there are no others yet. The Static Publisher locally works fine but swapping it out for RsyncMultiHostPublisher thrown a fatal.

Call to undefined method RsyncMultiHostPublisher::config() in /[site-root]/staticpublisher/code/extensions/RsyncMultiHostPublisher.php on line 68

Here's the code in mysite/_config.php - the silverstripe-staticpublisher is fresh from here this morning. I've tried Object::add_extension('SiteTree',... as well

SiteTree::add_extension("RsyncMultiHostPublisher('cache/', 'html')");
RsyncMultiHostPublisher::set_targets(array(
    '[user]@[ip]:/[webroot]',
));

Content type not cached

The content type of responses is not cached and so they are delivered as the server's default content type.

This is an issue for: XML sitemaps, JSON responses (if cached) and RSS feeds (for comments)

StaticImporter->doGeneratePages() should import index.html for wget URLs with trailing slashes

From http://open.silverstripe.org/ticket/4584

wget imports URLs like "parent/child/" (note trailing slash) into a file parent/child/index.html. StaticImporter? assumes URLs without trailing slashes: "parent/child" would import to parent/child.html.

This causes StaticImporter? to create three pages: "parent", "child" and "", where "" contains the content of index.html. This content should logically go into "child" instead, and "grandchild" should never be created.

Add a special case for index.html files into StaticImporter?. We might need a flag to enable this, and avoid putting imported (not generated) index.html files into the wrong hierarchy. Ideally the importer would detect trailing slashes in links and act accordingly.

Easy to replicate with a default wordpress installation (and "Day/Month?" style URLs).

@chillu

RebuildStaticCacheTask loads pages in Draft mode

In instances where multiple pages are cached, I'm seeing the cache being done on the draft version of the page.

I've set up my template to output the current stage to the page. If I publish a top-level page within the admin, it shows correctly as Stage.Live. If I cache a child page though, the child page is cached as Stage.Live, the parent page displays as Stage.Stage. Consequently, that page will show live and draft content.

I've tried forcing the ?stage=Live URL param onto the URL before caching within staticpublisher, but that doesn't change anything. Instead I altered the FilesytemPublisher PublishPages() function to temporary change the stage and that seemed to fix it.

I'm happy to submit a pull request with this change, but wanted to check if I'm missing something first.

Allow exporting of sitemap in a plaintext tab-indented format

From http://open.silverstripe.org/ticket/3552

As an extension to the importer, allow the sitemap of a Silverstripe to be exported in the same, tab-indented format.

This will make it easy to import into Optimal Workshop tools like http://www.optimalworkshop.com/treejack.htm

See http://open.silverstripe.com/browser/modules/sitetreeimporter/trunk/code/SiteTreeImporter.php

The module might be best renamed away from being 'importer' so that exporting makes sense in the code.

Not working with custom requirements backend

Since this publishPages method is using Director::test, it is not using the correct backend when exporting Pages (I use a different Requirements_Backend for the front-end and return to the default Requirements_Backend for the admin area).

Maybe a custom version of Director::test can be implemented to handle publishing pages?

Possible Bug with Object Extensions when Publishing Cache

I'm encountering an issue, which could possibly be a bug, where when publishing a pages cache the methods provided to it's object through a registered extension are not available and therefore the cached page is different to the page which is served up dynamically.

I haven't attempted to reproduce this with a clean install of Silverstripe and the latest version of the staticpublisher extension, so i could be reporting something that isn't a bug but is actually an issue with the code base i'm working on.

Here however is a rough example of what I'm encountering:

Extension:

    class SidebarMenuExtension extends DataExtension {
        public function testString() {
            return 'This is a test string';
        }
    }

Registering the extension:

    Object::add_extension("Page", "SidebarMenuExtension");

Template (hypothetically, Page.ss):

    $testString

When publishing the page and viewing dynamically, the test string would be output but when viewing the cached file nothing would be output.

I managed to work around this by registering a second extension, 'SidebarMenuExtensionController':

    class SidebarMenuExtensionController extends Extension {
        public function testString() {
            return 'This is a test string';
        }
    }

Which extends the Extension class (used for extending controllers), and registering it like so:

    Object::add_extension("Page_Controller", "SidebarMenuExtensionController");

However this seems a little convoluted so I'm wondering if this is a bug that either exists, used to exist and has been patched (but we havn't upgraded yet) or if this points to a more fundamental issue in the codebase I'm working on, or a fundamental mistake with my knowledge of how SS works.

Aden

GET vars invalidate cache

@wilr I notice you pushed in a feature to skip the cache if there are get vars. Any reason for this in particular?

I think we should add a feature to make get vars cachable; we'd likely need a whitelist of get vars like flush, isDev and so on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.