Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: check if rendered pages have proper title and description #38

Open
stereobooster opened this issue Nov 14, 2017 · 2 comments
Open

Comments

@stereobooster
Copy link
Owner

stereobooster commented Nov 14, 2017

If user bothered to do prerendering, lets make sure one will get max benefit out of it - I mean SEO (additionally to speed). Also possible to generate sitemap.xml. Also can check budgets for file sizes.

@stereobooster
Copy link
Owner Author

stereobooster commented Jan 5, 2018

Also we can use lighthouse to check

Related:

@erel
Copy link

erel commented Apr 28, 2019

Hey, I wrote a script that runs after react-snap that generate a sitemap.

const builder = require('xmlbuilder');
const { readdir, writeFile } = require('fs');
const { promisify } = require('util');

const asyncReaddir = promisify(readdir), asyncWriteFile = promisify(writeFile);

const asyncForEach = async (array, callback) => {
    for (let index = 0; index < array.length; index++) {
        await callback(array[index], index, array);
    }
}

let allRoots = [];

const readSite = async (dir) => {
    const directory = await asyncReaddir(dir, { withFileTypes: true });

    await asyncForEach(directory, async fileOrDirectory => {
        const { name } = fileOrDirectory;

        const root = `${dir}/${name}`;
        if (fileOrDirectory.isDirectory()) {
            await readSite(root);
        } else if (name === 'index.html') {
            allRoots = [...allRoots, root];
        }
    });
}

const blackList = ['https://whatever.com/some-page'];

(async () => {
    const baseUrl = 'https://whatever.com/';

    await readSite('build');

    const siteUrls = allRoots.map(root => root.replace('build/', baseUrl).replace('/index.html', ''));

    const urlset = builder.create('urlset', { encoding: 'UTF-8', version: '1.0' });

    urlset.attribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');

    siteUrls
        .filter(url => !blackList.includes(url))
        .sort((a, b) => a.length - b.length)
        .forEach(url => {
            const u = urlset.ele('url');

            u.ele('loc', url);
            u.ele('priority', 0.5);
        });

    const sitemap = urlset.end({ pretty: true });

    await asyncWriteFile('build/sitemap.xml', sitemap);
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants