als-layout 1.0.0 → 1.1.0

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/build-root.js CHANGED
@@ -1,8 +1,8 @@
1
- const { buildFromCache, Root, parseHTML } = require('als-document')
1
+ const { buildFromCache, Root, parseHTML, cacheDoc } = require('als-document')
2
2
 
3
3
  function buildRoot(item) {
4
4
  const root =
5
- (item instanceof Root) ? item
5
+ (item instanceof Root) ? buildFromCache(cacheDoc(item))
6
6
  : (typeof item === 'string') ? parseHTML(item)
7
7
  : (typeof item === 'object') ? buildFromCache(item)
8
8
  : new Root()
@@ -1,5 +1,5 @@
1
1
  const { Node } = require('als-document')
2
- function addScript(attributes={}, innerHTML, head = true, layout) {
2
+ function addScript(attributes={}, innerHTML='', head = true, layout) {
3
3
  if (attributes.src && layout.root.$(`script[src="${attributes.src}"]`)) return
4
4
  const script = new Node('script', attributes)
5
5
  script.innerHTML = innerHTML
@@ -1,12 +1,16 @@
1
1
  const addMeta = require('./add-meta')
2
- const {SingleNode} = require('als-document')
2
+ const { SingleNode } = require('als-document')
3
3
 
4
- function getUrl(url,host,layout) {
5
- url = new URL(url,host).href.replace(/\/$/,'')
6
- addMeta({property:'og:url',content:url},layout)
7
- const canonicalElement = layout.root.$('link[rel="canonical"]')
8
- if(canonicalElement) canonicalElement.setAttribute('href',url)
9
- else layout.head.insert(2,new SingleNode('link',{rel:'canonical',href:url}))
4
+ function getUrl(url, host, layout) {
5
+ try {
6
+ url = new URL(url, host).href.replace(/\/$/, '')
7
+ addMeta({ property: 'og:url', content: url }, layout)
8
+ const canonicalElement = layout.root.$('link[rel="canonical"]')
9
+ if (canonicalElement) canonicalElement.setAttribute('href', url)
10
+ else layout.head.insert(2, new SingleNode('link', { rel: 'canonical', href: url }))
11
+ } catch (error) {
12
+ console.log(`url ${url} with host ${host} is not valid url`)
13
+ }
10
14
  return layout
11
15
  }
12
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-layout",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Html layout constructor",
5
5
  "main": "index.js",
6
6
  "directories": {
package/readme.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Html layout constructor.
4
4
 
5
+ ## Change log
6
+ * clone - now it works
7
+ * script({},inner = '') default for inner for script is ''
8
+ * url - throwing error for not valid url
9
+
5
10
  ## install
6
11
 
7
12
  ```bash
@@ -15,7 +15,7 @@ describe('Basic tests', function () {
15
15
 
16
16
  it('should create an instance of Root from ready root', () => {
17
17
  const root = new Root()
18
- assert(buildRoot(root) === root)
18
+ assert(buildRoot(root) !== root)
19
19
  });
20
20
 
21
21
  it('should add !DOCTYPE', () => {