diff --git a/CHANGELOG.md b/CHANGELOG.md index c030c46..0117618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.11.0](https://github.com/CoCreate-app/CoCreate-css-parser/compare/v1.10.1...v1.11.0) (2023-09-17) + + +### Features + +* save css src with name, path, pathname and content-type ([572c34e](https://github.com/CoCreate-app/CoCreate-css-parser/commit/572c34e8ebd204b901bcc02742ba7824d90ff5be)) + ## [1.10.1](https://github.com/CoCreate-app/CoCreate-css-parser/compare/v1.10.0...v1.10.1) (2023-08-21) diff --git a/CoCreate.config.js b/CoCreate.config.js index 201359d..d69eb16 100644 --- a/CoCreate.config.js +++ b/CoCreate.config.js @@ -1,25 +1,25 @@ -module.exports = { - "organization_id": "", - "key": "", - "host": "", - "sources": [ - { - "array": "files", - "object": { - "_id": "637ca39950234ef1671ce312", - "name": "index.html", - "path": "/docs/css-parser/index.html", - "src": "{{./docs/index.html}}", - "host": [ - "cocreate.app", - "general.cocreate.app" - ], - "directory": "/docs/css-parser", - "parentDirectory": "{{parentDirectory}}", - "content-type": "{{content-type}}", - "public": "true", - "website_id": "644d4bff8036fb9d1d1fd69c" - } - } - ] -} \ No newline at end of file +module.exports = { + "organization_id": "", + "key": "", + "host": "", + "sources": [ + { + "array": "files", + "object": { + "_id": "637ca39950234ef1671ce312", + "name": "index.html", + "path": "/docs/css-parser/index.html", + "src": "{{./docs/index.html}}", + "host": [ + "cocreate.app", + "general.cocreate.app" + ], + "directory": "/docs/css-parser", + "parentDirectory": "{{parentDirectory}}", + "content-type": "{{content-type}}", + "public": "true", + "website_id": "644d4bff8036fb9d1d1fd69c" + } + } + ] +}; \ No newline at end of file diff --git a/package.json b/package.json index 2fffa30..49062be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cocreate/css-parser", - "version": "1.10.1", + "version": "1.11.0", "description": "A simple css-parser component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", "keywords": [ "css-parser", diff --git a/src/index.js b/src/index.js index cc7685a..6683ad0 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,8 @@ * * SPDX-License-Identifier: MIT ********************************************************************************/ + +/** */ import observer from '@cocreate/observer'; import localStorage from '@cocreate/local-storage'; @@ -42,13 +44,21 @@ function init(linkTag) { if (parse == 'true') { parseLinkCSS(); linkTag.getValue = () => { - const onlyUnique = (value, index, self) => { return self.indexOf(value) === index; }; - // let css = parsedCSS.concat(linkCSS).filter(onlyUnique); - // css.join('\r\n' - return parsedCSS.concat(linkCSS).filter(onlyUnique).join('\r\n') + + const urlObject = new URL(linkTag.href); + const pathParts = urlObject.pathname.split("/"); + + let data = {} + data.name = pathParts[pathParts.length - 1]; + data.path = urlObject.pathname.replace(data.name, ''); + data.pathname = urlObject.pathname; + data.src = parsedCSS.concat(linkCSS).filter(onlyUnique).join('\r\n'); + data['content-type'] = 'text/css'; + + return data } let elements = document.querySelectorAll("[class]"); initElements(elements);