1

I'm using Total.js CMS for my blog, but I want to export the complete HTML files from the database

I tried this code to export it

NOSQL('pages').find().callback(function(err, response) {
      response.forEach(function(page) {
            fs.writeFileSync(__dirname+'/content/index.html', page.body);
      });
});

But it only rendered the widgets that I'm using, not the full page.

How to do it properly? Thanks

Community
  • 1
  • 1
Ray
  • 75
  • 6

2 Answers2

0

First of all you are overwriting index.html but you need each page to go into its own file. But that still doesn't fix the issue you have since the page.body is rendered into ./themes/default/views/cms/default.html template which is rendered into ./themes/default/views/layout.html

Bellow code might do what you need:

NOSQL('pages').find().callback(function(err, response) {
      response.forEach(function(page) {
            fs.writeFileSync(__dirname+'/content/' + page.id + '.html', F.view('~/cms/default', {}, { page: { body: page.body }}));
      });
});
Molda
  • 5,619
  • 2
  • 23
  • 39
0

This is better solution. Create a definition file e.g. export and run your CMS. All pages will be stored in /public/render/ directory.

const Fs = require('fs');

function save() {
    NOSQL('pages').find().fields('id').callback(function(err, response) {
        var repository = {};
        var filter = {};
        var directory = F.path.public('/render/');
        try {
            Fs.mkdirSync(directory);
        } catch (e) {}
        response.waitFor(function(item, next) {
            filter.id = item.id;
            GETSCHEMA('Page').operation('render', filter, function(err, response) {
                repository.cms = true;
                repository.render = true;
                repository.page = response;
                Fs.writeFile(directory + response.title.slug() + '.html', F.view('~/cms/' + response.template, EMPTYOBJECT, '~/cms/layout', repository), next);
            });
        }, () => console.log('DONE'));
    });
}

F.on('ready', save);
Peter Sirka
  • 748
  • 5
  • 10