Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

akashacms-base

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

akashacms-base - npm Package Compare versions

Comparing version 0.6.8 to 0.7.0

partials/ak_toc_group_element.html.ejs

79

guide/index.html.md

@@ -8,4 +8,21 @@ ---

# Installation
<toc-group>
<toc-item id="install" title="Installation"></toc-item>
<toc-item id="config" title="Configuration"></toc-item>
<toc-item id="custom-tags" title="Custom tags">
<toc-group>
<toc-item id="metadata" title="Metadata in page header"></toc-item>
<toc-item id="link-rel" title="Generating link rel= tags in header"></toc-item>
<toc-item id="canonical-url" title="Generate a canonical URL in header"></toc-item>
<toc-item id="mktoc" title="Generate a Table of Contents for a page"></toc-item>
<toc-item id="publdate" title="Show the Publication Date on the page"></toc-item>
<toc-item id="opengraph" title="Promote images with OpenGraph tags"></toc-item>
<toc-item id="opengraph-single" title="Promoting a single image for OpenGraph"></toc-item>
</toc-group>
</toc-item>
<toc-item id="sitemaps" title="XML Sitemaps"></toc-item>
</toc-group>
<h1 id="install">Installation</h1>
With an AkashaCMS website setup, add the following to `package.json`

@@ -16,3 +33,3 @@

...
"akashacms-base": ">0.6",
"akashacms-base": "0.7.0",
...

@@ -24,18 +41,18 @@ }

# Configuration
<h1 id="config">Configuration</h1>
In `config.js` for the website:
```js
config.use(require('akashacms-base'), {
generateSitemapFlag: true
});
```
config.use(require('akashacms-base'));
config.plugin("akashacms-base").generateSitemap(config, true);
```
The `generateSitemapFlag` flag causes an XML Sitemap to be generated in the file `/sitemap.xml`. See the XML Sitemaps section below.
The latter causes an XML Sitemap to be generated in the file `/sitemap.xml`. See the XML Sitemaps section below.
<h1 id="custom-tags">Custom tags</h1>
# Custom tags
<h2 id="metadata">Metadata in page header</h2>
## Metadata in page header
There's a lot of metadata, Open Graph etc, that can be put into the `<head>` section. These tags are useful for customizing the presentation in search engines or on social media websites.

@@ -47,3 +64,3 @@

## Generating link rel= tags in header
<h2 id="link-rel">Generating link rel= tags in header</h2>

@@ -76,3 +93,3 @@ Header tags of the pattern `<link rel="..." href="..."/>` are used for many purposes. AkashaCMS-Base supports simplified method to generate these tags

## Generate a canonical URL in header
<h2 id="canonical-url">Generate a canonical URL in header</h2>

@@ -83,4 +100,34 @@ The `canonical` link tag defines the most correct official URL for the page. It's used by search engines to disambiguate pages that might appear under multiple URL's.

## Show the Publication Date on the page
<h2 id="mktoc">Generate a Table of Contents for a page</h2>
Many websites have a "table of contents" block at the top of a page to help navigate the page. It's simply a list (possibly nested list) of links to locations within the page.
With `<toc-group>` we generate a container for such a table of contents. Attributes are:
* `template` for an alternative to the standard template (`ak_toc_group_element.html.ejs`)
* `id` for the ID of the `toc-group`
* `additional-classes` for additional class declarations to add to the `class` attribute
This element is expected to contain `<toc-item>` elements that will be the links to locations within the page. Attributes to this element are:
* `template` for an alternative to the standard template (`ak_toc_group_element.html.ejs`)
* `id` for the ID of the `toc-group`
* `additional-classes` for additional class declarations to add to the `class` attribute
* `title` for the anchor text in the generated link
* `anchor` for the href to use in the generated link
Any additional markup will be inserted into the generated list item after the link. The primary use for this will be to have a nested `<toc-group>`.
To implement a "_return to top_" link, simply scatter something like this throughout the page:
```html
<div style="clear: both">
<a href="#ID-FOR-TOC-GROUP">[return to top]</a>
</div>
```
The `<toc-group>` must, in this case, have an `id` attribute. Your link would use that `id` in the `href` as shown here.
<h2 id="publdate">Show the Publication Date on the page</h2>
It's often desirable to show the publication date for a page. It's often desirable for the page metadata to include the `publicationDate` for a variety of purposes. For example the `akashacms-blog-podcast` plugin uses the publicationDate to sort content.

@@ -92,3 +139,3 @@

## Promote images with OpenGraph tags
<h2 id="opengraph">Promote images with OpenGraph tags</h2>

@@ -107,3 +154,3 @@ The the banner image in social media website posts is derived from images listed in OpenGraph tags. We all want our web content to have a good appearance on social media sites. Having a good quality image is key to that goal.

## Promoting a single image for OpenGraph
<h2 id="opengraph-single">Promoting a single image for OpenGraph</h2>

@@ -116,4 +163,4 @@ The previous tag handles promoting multiple images from a given section of a page. If you have a single image to promote, this tag will do the trick.

# XML Sitemaps
<h1 id="sitemaps">XML Sitemaps</h1>
The sitemap will list any file rendered using HTMLRenderer. See https://www.sitemaps.org/index.html for information about XML Sitemaps.
/**
*
* Copyright 2014-2017 David Herron
* Copyright 2014-2019 David Herron
*

@@ -20,4 +20,2 @@ * This file is part of AkashaCMS (http://akashacms.com/).

'use strict';
const fs = require('fs');

@@ -29,9 +27,9 @@ const path = require('path');

const mahabhuta = akasha.mahabhuta;
const smap = require('sightmap');
const smap = require('sightmap');
const log = require('debug')('akasha:base-plugin');
const error = require('debug')('akasha:error-base-plugin');
const pluginName = "akashacms-base";
const _plugin_config = Symbol('config');
const _plugin_options = Symbol('options');
module.exports = class BasePlugin extends akasha.Plugin {

@@ -42,16 +40,24 @@ constructor() {

configure(config) {
configure(config, options) {
this[_plugin_config] = config;
this[_plugin_options] = options;
options.config = config;
config.addPartialsDir(path.join(__dirname, 'partials'));
config.addLayoutsDir(path.join(__dirname, 'layout'));
config.addAssetsDir(path.join(__dirname, 'assets'));
config.addMahabhuta(module.exports.mahabhuta);
config.pluginData(pluginName).linkRelTags = [];
config.addMahabhuta(module.exports.mahabhutaArray(options));
this[_plugin_options].linkRelTags = [];
}
get config() { return this[_plugin_config]; }
get options() { return this[_plugin_options]; }
doHeaderMetaSync(config, metadata) {
return akasha.partialSync(config, "ak_headermeta.html.ejs", fixHeaderMeta(metadata));
return akasha.partialSync(config,
"ak_headermeta.html.ejs",
fixHeaderMeta(metadata));
}
addLinkRelTag(config, lrTag) {
config.pluginData(pluginName).linkRelTags.push(lrTag);
this.options.linkRelTags.push(lrTag);
return this;

@@ -73,3 +79,3 @@ }

generateSitemap(config, doit) {
config.pluginData(pluginName).generateSitemapFlag = doit;
this.options.generateSitemapFlag = doit;
return this;

@@ -79,3 +85,3 @@ }

async onSiteRendered(config) {
if (!config.pluginData(pluginName).generateSitemapFlag) {
if (!this.options.generateSitemapFlag) {
return Promise.resolve("skipped");

@@ -130,61 +136,70 @@ }

module.exports.mahabhuta = new mahabhuta.MahafuncArray("akashacms-base", {});
module.exports.mahabhutaArray = function(options) {
let ret = new mahabhuta.MahafuncArray(pluginName, options);
ret.addMahafunc(new HeaderMetatagsElement());
ret.addMahafunc(new XMLSitemap());
ret.addMahafunc(new LinkRelTagsElement());
ret.addMahafunc(new CanonicalURLElement());
ret.addMahafunc(
function($, metadata, dirty, done) {
var elements = [];
$('ak-siteverification').each((i, elem) => { elements.push(elem); });
if (elements.length <= 0) return done();
return done(new Error("ak-siteverification deprecated, use site-verification instead"));
});
ret.addMahafunc(new GoogleAnalyticsElement());
ret.addMahafunc(new PublicationDateElement());
ret.addMahafunc(new TOCGroupElement());
ret.addMahafunc(new TOCItemElement());
ret.addMahafunc(new AuthorLinkElement());
ret.addMahafunc(new OpenGraphImage());
ret.addMahafunc(new OpenGraphPromoteImages());
return ret;
};
var fixHeaderMeta = function(metadata) {
var data = {};
for (var prop in metadata) {
if (!(prop in data)) data[prop] = metadata[prop];
}
if (typeof data.metaOGtitle === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metaOGtitle = data.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metaOGtitle = data.title;
}
}
if (typeof data.metaOGdescription === "undefined") {
if (typeof data.metadescription !== "undefined") {
data.metaOGdescription = data.metadescription;
}
}
if (typeof data.metaDCtitle === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metaDCtitle = arg.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metaDCtitle = data.title;
}
}
if (typeof data.metapagename === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metapagename = arg.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metapagename = data.title;
}
}
if (typeof data.metadate === "undefined") {
data.metadate = data.rendered_date;
}
return data;
var data = {};
for (var prop in metadata) {
if (!(prop in data)) data[prop] = metadata[prop];
}
if (typeof data.metaOGtitle === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metaOGtitle = data.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metaOGtitle = data.title;
}
}
if (typeof data.metaOGdescription === "undefined") {
if (typeof data.metadescription !== "undefined") {
data.metaOGdescription = data.metadescription;
}
}
if (typeof data.metaDCtitle === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metaDCtitle = arg.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metaDCtitle = data.title;
}
}
if (typeof data.metapagename === "undefined") {
if (typeof data.pagetitle !== "undefined") {
data.metapagename = arg.pagetitle;
} else if (typeof data.title !== "undefined") {
data.metapagename = data.title;
}
}
if (typeof data.metadate === "undefined") {
data.metadate = data.rendered_date;
}
return data;
};
var akDoHeaderMeta = function(metadata) {
return akasha.partial(metadata.config, "ak_headermeta.html.ejs", fixHeaderMeta(metadata));
};
/* TOO SILLY */
class PageTitleElement extends mahabhuta.CustomElement {
get elementName() { return "ak-page-title"; }
process($element, metadata, dirty) {
return Promise.reject(new Error("ak-page-title deprecated"));
}
}
module.exports.mahabhuta.addMahafunc(new PageTitleElement()); /* */
class HeaderMetatagsElement extends mahabhuta.CustomElement {
get elementName() { return "ak-header-metatags"; }
process($element, metadata, dirty, done) {
return akDoHeaderMeta(metadata);
}
get elementName() { return "ak-header-metatags"; }
process($element, metadata, dirty) {
return akasha.partial(this.array.options.config,
"ak_headermeta.html.ejs",
fixHeaderMeta(metadata));
}
}
module.exports.mahabhuta.addMahafunc(new HeaderMetatagsElement());

@@ -194,13 +209,13 @@ /* Moved to Mahabhuta */

get elementName() { return "ak-sitemapxml"; }
process($element, metadata, dirty, done) {
process($element, metadata, dirty) {
return Promise.reject(new Error("ak-sitemapxml deprecated"));
}
}
module.exports.mahabhuta.addMahafunc(new XMLSitemap()); /* */
function doLinkRelTag(config, lrtag) {
return akasha.partial(metadata.config, "ak_linkreltag.html.ejs", {
relationship: lrtag.relationship,
url: lrtag.url
});
return `<link rel="${lrtag.relationship}" href="${lrtag.url}" />`;
// return akasha.partial(this.array.options.config, "ak_linkreltag.html.ejs", {
// relationship: lrtag.relationship,
// url: lrtag.url
// });
}

@@ -210,12 +225,12 @@

get elementName() { return "ak-header-linkreltags"; }
async process($element, metadata, dirty) {
process($element, metadata, dirty) {
var ret = "";
if (metadata.config.pluginData(pluginName).linkRelTags.length > 0) {
for (var lrtag of metadata.config.pluginData(pluginName).linkRelTags) {
ret += await doLinkRelTag(metadata.config, lrtag);
if (this.array.options.linkRelTags.length > 0) {
for (var lrtag of this.array.options.linkRelTags) {
ret += doLinkRelTag(this.array.options.config, lrtag);
}
}
if (metadata.config.pluginData(pluginName).linkRelTags.length > 0) {
for (var lrtag of metadata.config.pluginData(pluginName).linkRelTags) {
ret += await doLinkRelTag(metadata.config, lrtag);
if (this.array.options.linkRelTags.length > 0) {
for (var lrtag of this.array.options.linkRelTags) {
ret += doLinkRelTag(this.array.options.config, lrtag);
}

@@ -226,3 +241,2 @@ }

}
module.exports.mahabhuta.addMahafunc(new LinkRelTagsElement());

@@ -232,3 +246,3 @@ class CanonicalURLElement extends mahabhuta.CustomElement {

process($element, metadata, dirty) {
return doLinkRelTag(metadata.config, {
return doLinkRelTag(this.array.options.config, {
relationship: "canonical",

@@ -239,12 +253,3 @@ url: metadata.rendered_url

}
module.exports.mahabhuta.addMahafunc(new CanonicalURLElement());
module.exports.mahabhuta.addMahafunc(
function($, metadata, dirty, done) {
var elements = [];
$('ak-siteverification').each((i, elem) => { elements.push(elem); });
if (elements.length <= 0) return done();
return done(new Error("ak-siteverification deprecated, use site-verification instead"));
});
class GoogleAnalyticsElement extends mahabhuta.CustomElement {

@@ -256,16 +261,68 @@ get elementName() { return "ak-google-analytics"; }

}
module.exports.mahabhuta.addMahafunc(new GoogleAnalyticsElement());
class PublicationDateElement extends mahabhuta.CustomElement {
get elementName() { return "publication-date"; }
process($element, metadata, dirty, done) {
async process($element, metadata, dirty) {
if (metadata.publicationDate) {
return akasha.partial(metadata.config, "ak_publdate.html.ejs", {
return akasha.partial(this.array.options.config, "ak_publdate.html.ejs", {
publicationDate: metadata.publicationDate
});
} else return Promise.resolve("");
} else return "";
}
}
module.exports.mahabhuta.addMahafunc(new PublicationDateElement());
class TOCGroupElement extends mahabhuta.CustomElement {
get elementName() { return "toc-group"; }
async process($element, metadata, dirty) {
const template = $element.attr('template')
? $element.attr('template')
: "ak_toc_group_element.html.ejs";
const id = $element.attr('id');
const additionalClasses = $element.attr('additional-classes')
? $element.attr('additional-classes')
: "";
const suppressContents = $element.attr('suppress-contents');
const content = $element.html()
? $element.html()
: "";
return akasha.partial(this.array.options.config, template, {
id, additionalClasses, suppressContents,
content
});
}
}
class TOCItemElement extends mahabhuta.CustomElement {
get elementName() { return "toc-item"; }
async process($element, metadata, dirty) {
const template = $element.attr('template')
? $element.attr('template')
: "ak_toc_item_element.html.ejs";
const id = $element.attr('id');
const additionalClasses = $element.attr('additional-classes')
? $element.attr('additional-classes')
: "";
const title = $element.attr('title');
if (!title || title === '') {
throw new Error(`toc-item requires an title value`);
}
const anchor = $element.attr('anchor');
if (!anchor || anchor === '') {
throw new Error(`toc-item requires an anchor value`);
}
const content = $element.html()
? $element.html()
: "";
return akasha.partial(this.array.options.config, template, {
id, additionalClasses, title, anchor,
content
});
}
}
// TODO revamp this

@@ -277,9 +334,9 @@ // TODO this doesn't seem to be used anywhere so I haven't tested it.

throw new Error("author-link disabled");
/* if (typeof metadata.config.authorship === 'undefined') {
/* if (typeof this.array.options.config.authorship === 'undefined') {
return Promise.resolve("");
}
var author;
for (var i in metadata.config.authorship.authors) {
if (metadata.config.authorship.authors[i].name === auname) {
author = metadata.config.authorship.authors[i];
for (var i in this.array.options.config.authorship.authors) {
if (this.array.options.config.authorship.authors[i].name === auname) {
author = this.array.options.config.authorship.authors[i];
break;

@@ -289,3 +346,3 @@ }

if (author) {
return akasha.partial(metadata.config, "ak_authorship.html.ejs", {
return akasha.partial(this.array.options.config, "ak_authorship.html.ejs", {
fullname: author.fullname,

@@ -300,3 +357,2 @@ authorship: author.authorship

}
module.exports.mahabhuta.addMahafunc(new AuthorLinkElement());

@@ -307,4 +363,4 @@ class OpenGraphImage extends mahabhuta.Munger {

const href = $link.attr('href');
if ($(`meta[content="${href}"]`).get(0) === undefined) {
let txt = await akasha.partial(metadata.config, 'ak_metatag.html.ejs', {
if (href && $(`meta[content="${href}"]`).get(0) === undefined) {
let txt = await akasha.partial(this.array.options.config, 'ak_metatag.html.ejs', {
tagname: 'og:image',

@@ -320,3 +376,2 @@ tagcontent: href

}
module.exports.mahabhuta.addMahafunc(new OpenGraphImage());

@@ -359,7 +414,7 @@ class OpenGraphPromoteImages extends mahabhuta.Munger {

if (pHref.path.match(/^\//)) {
href = metadata.config.root_url + href;
href = this.array.options.config.root_url + href;
} else {
let pRendered = url.parse(metadata.rendered_url);
let dirRender = path.dirname(pRendered.path);
let pRootUrl = url.parse(metadata.config.root_url);
let pRootUrl = url.parse(this.array.options.config.root_url);
pRootUrl.pathname = dirRender +'/'+ href;

@@ -371,3 +426,3 @@ href = url.format(pRootUrl);

if ($(`meta[content="${href}"]`).get(0) === undefined) {
let txt = await akasha.partial(metadata.config, 'ak_metatag.html.ejs', {
let txt = await akasha.partial(this.array.options.config, 'ak_metatag.html.ejs', {
tagname: 'og:image',

@@ -388,94 +443,1 @@ tagcontent: href

}
module.exports.mahabhuta.addMahafunc(new OpenGraphPromoteImages());
/* This is now in akashacms-external-links
*
module.exports.mahabhuta.addMahafunc(
function($, metadata, dirty, done) {
var links = [];
$('html body a').each((i, elem) => { links.push(elem); });
if (links.length <= 0) return done();
log('a modifications');
async.eachSeries(links,
(link, next) => {
setImmediate(function() {
var href = $(link).attr('href');
// The potential exists to manipulate links to local documents
// Such as what's done with the linkto tag above.
// Such as checking for valid links
// Also need to consider links to //hostname/path/to/object
// Potential for complete link checking service right here
if (href && href !== '#') {
var uHref = url.parse(href, true, true);
if (uHref.protocol || uHref.slashes) {
// It's a link to somewhere else
// look at domain in whitelist and blacklist
var donofollow = false;
if (metadata.config.nofollow && metadata.config.nofollow.blacklist) {
metadata.config.nofollow.blacklist.forEach(function(re) {
if (uHref.hostname.match(re)) {
donofollow = true;
}
});
}
if (metadata.config.nofollow && metadata.config.nofollow.whitelist) {
metadata.config.nofollow.whitelist.forEach(function(re) {
if (uHref.hostname.match(re)) {
donofollow = false;
}
});
}
if (donofollow && !$(link).attr('rel')) {
$(link).attr('rel', 'nofollow');
}
/* TODO
if (! metadata.config.builtin.suppress.extlink
&& $(link).find("img.ak-extlink-icon").length <= 0) {
$(link).append('<img class="ak-extlink-icon" src="/img/extlink.png"/>');
} * /
next();
} else {
// This is where we would handle local links
if (! href.match(/^\//)) {
var hreforig = href;
var pRenderedUrl = url.parse(metadata.rendered_url);
var docpath = pRenderedUrl.pathname;
var docdir = path.dirname(docpath);
href = path.join(docdir, href);
// util.log('***** FIXED href '+ hreforig +' to '+ href);
}
/* TODO
var docEntry = akasha.findDocumentForUrlpath(href);
if (docEntry) {
// Automatically add a title= attribute
if (!$(link).attr('title') && docEntry.frontmatter.yaml.title) {
$(link).attr('title', docEntry.frontmatter.yaml.title);
}
// For local links that don't have text or interior nodes,
// supply text from the title of the target of the link.
var linktext = $(link).text();
if ((!linktext || linktext.length <= 0 || linktext === href)
&& $(link).children() <= 0
&& docEntry.frontmatter.yaml.title) {
$(link).text(docEntry.frontmatter.yaml.title);
}
} * /
next();
}
} else next();
});
},
err => {
if (err) done(err);
else done();
});
}); */

@@ -29,10 +29,9 @@ {

},
"version": "0.6.8",
"version": "0.7.0",
"engines": {
"node": ">=8.4"
"node": ">=12.2"
},
"dependencies": {
"debug": "^2.2.0",
"sightmap": "*"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc