sbg-api
Version:
Pre-processing all source posts before rendering from hexo. Useful for low-end devices to prevent using large number of hexo plugins.
53 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.taskSeo = void 0;
var tslib_1 = require("tslib");
var ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
var gulp_1 = tslib_1.__importDefault(require("gulp"));
var sbg_utility_1 = require("sbg-utility");
/**
* Auto seo runner
* @param cwd working directory to scan html's
*/
function taskSeo(_done, cwd) {
var config = (0, sbg_utility_1.getConfig)();
var ignore = Array.isArray(config.exclude) ? config.exclude : [];
ignore.push.apply(ignore, tslib_1.__spreadArray([], tslib_1.__read(sbg_utility_1.commonIgnore), false));
return gulp_1.default
.src(['**/*.{htm,html}', '*.{html,htm}'], { cwd: cwd, ignore: ignore })
.pipe((0, sbg_utility_1.gulpCached)({ name: 'seo' }))
.pipe((0, sbg_utility_1.gulpDom)(function (path) {
var _this = this;
// fix alt images
var images = Array.from(this.querySelectorAll('img[src]'));
images.forEach(function (el) {
var alt = el.getAttribute('alt');
if (!alt || alt.length === 0) {
var title = _this.title + ' - ' + el.getAttribute('src') || 'No Alt';
el.setAttribute('alt', title);
}
});
// fix title iframe
var iframes = Array.from(this.querySelectorAll('iframe[src]'));
iframes.forEach(function (el) {
var alt = el.getAttribute('title');
if (!alt || alt.length === 0) {
var title = _this.title + ' - ' + el.getAttribute('src') || 'No Title';
el.setAttribute('title', title);
}
});
// WARNING MAKER
// count H1
var h1 = this.querySelectorAll('h1');
if (h1.length > 1) {
sbg_utility_1.Logger.log(ansi_colors_1.default.yellowBright('[WARN]'), "H1 (".concat(h1.length, ") ").concat(path));
}
}))
.pipe(gulp_1.default.dest(cwd));
}
exports.taskSeo = taskSeo;
gulp_1.default.task('seo', function () {
var deployDir = (0, sbg_utility_1.deployConfig)().deployDir;
return taskSeo(null, deployDir);
});
//# sourceMappingURL=gulp.seo.js.map