als-layout 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/elements/image.js +3 -1
- package/lib/elements/link.js +2 -1
- package/lib/elements/script.js +6 -4
- package/lib/layout.js +4 -3
- package/package.json +2 -2
- package/readme.md +8 -6
package/lib/elements/image.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const addMeta = require('./add-meta')
|
|
2
|
-
function addImage(image,layout) {
|
|
2
|
+
function addImage(image,version, layout) {
|
|
3
|
+
if (image && version) image += src.includes('?') ? '&' : '?' + `v=${version}`
|
|
4
|
+
|
|
3
5
|
addMeta({property:'og:image',content:image},layout)
|
|
4
6
|
addMeta({name:'twitter:image',content:image},layout)
|
|
5
7
|
addMeta({name:'twitter:card',content:'summary_large_image'},layout)
|
package/lib/elements/link.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { SingleNode } = require('als-document')
|
|
2
|
-
function addLink(href, layout) {
|
|
2
|
+
function addLink(href, version, layout) {
|
|
3
3
|
let linkElement = layout.root.$(`link[rel=stylesheet][href="${href}"]`)
|
|
4
4
|
if (linkElement) return
|
|
5
|
+
if (href && version) href += href.includes('?') ? '&' : '?' + `v=${version}`
|
|
5
6
|
linkElement = new SingleNode('link', { rel: 'stylesheet', href })
|
|
6
7
|
layout.head.insert(2, linkElement)
|
|
7
8
|
return layout
|
package/lib/elements/script.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const { Node } = require('als-document')
|
|
2
|
-
function addScript(
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
function addScript(attrs = {}, innerHTML = '', head = true, version, layout) {
|
|
3
|
+
const { src } = attrs
|
|
4
|
+
if (src && layout.root.$(`script[src="${attrs.src}"]`)) return
|
|
5
|
+
if (src && version) attrs.src += src.includes('?') ? '&' : '?' + `v=${version}`
|
|
6
|
+
const script = new Node('script', attrs)
|
|
5
7
|
script.innerHTML = innerHTML
|
|
6
|
-
if(head) layout.root.head.insert(2, script)
|
|
8
|
+
if (head) layout.root.head.insert(2, script)
|
|
7
9
|
else layout.body.insert(3, script)
|
|
8
10
|
return layout
|
|
9
11
|
}
|
package/lib/layout.js
CHANGED
|
@@ -34,15 +34,16 @@ class Layout {
|
|
|
34
34
|
get cached() { return cacheDoc(this.root) }
|
|
35
35
|
get clone() { return new Layout(this.root, this.options) }
|
|
36
36
|
|
|
37
|
+
version(v) {this.v = v; return this;}
|
|
37
38
|
keywords(keywords = []) { return addKeywords(keywords, this) }
|
|
38
39
|
description(description) { return addDescription(description, this) }
|
|
39
40
|
title(title) { return addTitle(title, this) }
|
|
40
41
|
style(styles, minified) { return addStyle(styles, minified, this) }
|
|
41
|
-
image(image) { return addImage(image, this) }
|
|
42
|
+
image(image,v=this.v) { return addImage(image, v, this) }
|
|
42
43
|
url(url, host = this.options.host) { return addUrl(url, host, this) }
|
|
43
44
|
favicon(href) { return addFavicon(href, this) }
|
|
44
|
-
script(attributes, innerHTML, head = true) { return addScript(attributes, innerHTML, head, this) }
|
|
45
|
-
link(href) { return addLink(href, this) }
|
|
45
|
+
script(attributes, innerHTML, head = true, v=this.v) { return addScript(attributes, innerHTML, head, v, this) }
|
|
46
|
+
link(href, v=this.v) { return addLink(href, v, this) }
|
|
46
47
|
charset(newCharset = 'UTF-8') { return charset(newCharset, this) }
|
|
47
48
|
viewport(newViewport = 'width=device-width, initial-scale=1.0') { return viewport(newViewport, this) }
|
|
48
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "als-layout",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Html layout constructor",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"als-css-parser": "^0.5.0",
|
|
17
|
-
"als-document": "^1.0.
|
|
17
|
+
"als-document": "^1.0.2",
|
|
18
18
|
"als-simple-css": "^8.0.0"
|
|
19
19
|
}
|
|
20
20
|
}
|
package/readme.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Html layout constructor.
|
|
4
4
|
|
|
5
5
|
## Change log
|
|
6
|
-
*
|
|
7
|
-
* script
|
|
8
|
-
*
|
|
6
|
+
* version method
|
|
7
|
+
* script,link,image - version parameter
|
|
8
|
+
* updated als-document version
|
|
9
9
|
|
|
10
10
|
## install
|
|
11
11
|
|
|
@@ -23,13 +23,14 @@ const layout = new Layout()
|
|
|
23
23
|
.title('Test title') // adding/updating title and meta[og:title]
|
|
24
24
|
.favicon('/favicon.png') // adding/updating link[rel=icon][type=image/x-icon] with new href
|
|
25
25
|
.keywords(['some','keyword']) // adding/updating meta[name=keywords]. not adding existing keywords
|
|
26
|
-
.image('/main-image.png') // adding/updating meta - og:image,twitter:image,twitter:card
|
|
26
|
+
.image('/main-image.png','1.5') // adding/updating meta - og:image,twitter:image,twitter:card
|
|
27
27
|
.description('Cool site') // adding/updating meta og:description,twitter:description and description tag
|
|
28
|
+
.version('1.0.0') // adds version parameter to link, script.src and image
|
|
28
29
|
.url('/some', 'http://site.com') // adding/updating meta[og:url] and link[rel="canonical"]
|
|
29
30
|
.style([{body:{m:0,bgc:'whitesmoke'}}]) // adding as simple-css styles to existing/new style tag
|
|
30
31
|
.style('body {margin:0; backgroung-color:whitesmoke;}',true) // adding css styles to existing/new style tag. Second parameter is minified (default=false).
|
|
31
|
-
.link('/styles.css') // adding link[rel=stylesheet] if such href not exists
|
|
32
|
-
.script({src:'/app.js'},'', true) // set script with src to head if such src not exists
|
|
32
|
+
.link('/styles.css','2.0') // adding link[rel=stylesheet] if such href not exists
|
|
33
|
+
.script({src:'/app.js'},'', true,'3.0') // set script with src to head if such src not exists
|
|
33
34
|
.script({}, 'console.log("hello world")', false) // set script with script code to footer
|
|
34
35
|
|
|
35
36
|
|
|
@@ -42,6 +43,7 @@ layout.cached // cached DOM
|
|
|
42
43
|
layout.clone // new layout object clone for curent object
|
|
43
44
|
```
|
|
44
45
|
|
|
46
|
+
In image, script.src and link, last parameter is version which using 'layout.v' (defined by layout.version(v)) if not defined.
|
|
45
47
|
|
|
46
48
|
## Advanced usage
|
|
47
49
|
|