• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

Script like Chevereto-Docs

Avast

👽 Chevereto Freak
I really like the system of chevereto-docs:
How the url looks like,
How the content is delivered,
And the parameters.

So Rodolfo, please tell me how you did it 😉
I think you've done something to the .htaccess too, please explain what .

Regards, Avast
 
Sure, the system uses AJAX to load the docs and it complies with the Google Specification on Ajax URLs. There are the main elements of the system, use it as a base.

Files needed
On the server side you will need to set a loader for all your files. In Chevereto I use something called "docs_loader.php" which accept a query string to pass what page I want to lead. You will also need a JS (with jQuery) to perfom the ajax call.

docs_loader.php
This example works by loading static files on the server, but it can work with any method that you use to store the pages.
PHP:
$page = $_GET['page'];
$docs_files = array_values(array_diff(scandir('yourdir'), array('.', '..')));
 
$referer = parse_url($_SERVER['HTTP_REFERER']);
 
if(in_array($page.'.php', $docs_files) and $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest' and preg_match('/chevereto.com/', $referer['host'])) {
    include('yourdir/'.$page.'.php');
} else {
    header('HTTP/1.1 400 Bad Request');
    echo '400 Bad Request';
}

I use in_array instead of file_existsbecause I haven't clean the GET and in that way I strictly allow only the docs that exists. I set-up a couple of conditionals to ensure that this call is only comes from AJAX and your own domain, and then include the page.

Note about _escaped_fragment_
If you load pages with Ajax and you don't set the _escaped_fragment_ workaround Google won't index that Ajax pages. To get your Ajax pages indexed Google has come out with a simple solution, #! is replaced with ?_escaped_fragment_= and keep you indexed as #!. To get this you have to set a non-ajaxed version of the page. In Chevereto http://chevereto.com/docs#!server-configuration has a escaped version on http://chevereto.com/docs?_escaped_fragment_=server-configuration, to get this static version well... You need to get the escaped fragment value and load just like any other PHP page.

JavaScript
LOAD
You can do it by doing a AJAX call, a $.GET or a even simple load. The important here is that the loader is defined as a function. In this example I've replaced the #! from the hash so you I don't need to deal with that in the docs_loader.php.
Code:
function loadDocs() {
    $(main_col).load('/content/docs_loader.php?page='+document.location.hash.replace('#!',''), function(response, status, xhr) {
        $('.loading').fadeOut(1000, function() { $(this).remove(); });
        var h2title = $(main_col+' h2').html();
        if (status == "error") {
            document.title = doctitle;
            $(main_col).html('404');
        } else {
            document.title = doctitle+' | '+h2title;
        }       
        _gaq.push(['_trackPageview', "/docs/?_escaped_fragment_="+normal_hash.replace('#','')]);
    }).hide().fadeIn('slow');
}

RESPONSIVE HASH
The load was defined as a function because you want that this loader works with hash change, meaning that the hash could be shared, acceded directly, triggered by a link, etc. To make the hash change always load the desired doc you need to have this code in your JavaScript:
Code:
// Bind on hashchange...
$(window).bind('hashchange', function() {
    if(!window.location.hash) {
        window.location.hash = '#!introduction';
    }
    loadDocs(); // This keeps back/foward button
});
 
// Saves the hash...
if(window.location.hash) {
    loadDocs();
}
 
Nice 😉 i don't knew that google doesn't index sites without the fragment.
Ok and how do the documents-files look like?
 
Back
Top