@data-visuals/create 7.6.1 → 7.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-visuals/create",
3
- "version": "7.6.1",
3
+ "version": "7.6.3",
4
4
  "description": "Create graphics and features the Data Visuals way.",
5
5
  "scripts": {
6
6
  "build:docs": "doctoc README.md --github",
@@ -73,3 +73,12 @@
73
73
  }
74
74
  }
75
75
  }
76
+
77
+ // figma2html
78
+ i {
79
+ font-style: italic;
80
+ }
81
+
82
+ b {
83
+ font-weight: bold;
84
+ }
@@ -142,3 +142,12 @@
142
142
  max-width: 24em;
143
143
  }
144
144
  }
145
+
146
+ // figma2html
147
+ i {
148
+ font-style: italic;
149
+ }
150
+
151
+ b {
152
+ font-weight: bold;
153
+ }
@@ -0,0 +1,26 @@
1
+ <script>
2
+ const figma2html = document.querySelector('.figma2html');
3
+
4
+ // Tweak image sources
5
+ const images = figma2html.querySelectorAll('img.f2h-img');
6
+ images.forEach(image => {
7
+ let src = image.getAttribute('data-src');
8
+ if (!src.includes('../')) {
9
+ src = '../' + src;
10
+ }
11
+ image.setAttribute('src', src);
12
+ })
13
+
14
+ // add CSS media queries as style text
15
+ const style = document.createElement('style')
16
+ figma2html.appendChild(style);
17
+
18
+ const frames = figma2html.querySelectorAll('.f2h-frame');
19
+
20
+ // dynamically add css styles as text
21
+ if (frames.length == 2) {
22
+ style.textContent = '#f2h-frame-664 { display: block !important; } #f2h-frame-320 { display: none !important; } @media (max-width: 664px) { #f2h-frame-664 { display: none !important; } #f2h-frame-320 { display: block !important; }}'
23
+ } else {
24
+ style.textContent = '#f2h-frame-1040 { display: block !important; } #f2h-frame-664, #f2h-frame-320 { display: none !important; } @media (max-width: 1040px) { #f2h-frame-1040, #f2h-frame-320 { display: none !important; } #f2h-frame-664 { display: block !important; }} @media (max-width: 664px) { #f2h-frame-1040, #f2h-frame-664 { display: none !important; } #f2h-frame-320 { display: block !important; }}'
25
+ }
26
+ </script>
@@ -7,110 +7,124 @@ const paths = require('../paths');
7
7
  const { resolve } = require('path');
8
8
 
9
9
  // functions
10
- const moveHtml = filename => {
11
- // move the .html file in the app/templates directory
12
- fs.renameSync(
13
- 'workspace/' + filename + '.html',
14
- 'app/templates/figma2html-output/' + filename + '.html'
15
- );
16
- };
10
+ const extractZip = async file => {
11
+ console.log('Unzipping ' + colors.magentaBright(file) + '...');
17
12
 
18
- const moveImages = filename => {
19
- // move the image files in the app/assets/figma2html/FILENAME directory
20
- const imagesPath = 'workspace/assets/figma2html/' + filename;
21
- fs.readdir(imagesPath, (err, images) => {
22
- images.forEach(image => {
23
- console.log('moving ' + image + '...');
24
- fs.renameSync(
25
- imagesPath + '/' + image,
26
- 'app/assets/figma2html/' + filename + '/' + image
27
- );
28
- });
29
- });
30
- };
13
+ try {
14
+ // extract the zip file
15
+ await extract(
16
+ resolve('workspace/figma2html-exports/' + file),
17
+ // save the extracted zip file in the workspace directory
18
+ { dir: resolve('workspace/figma2html-exports') }
19
+ );
31
20
 
32
- const moveFiles = filename => {
33
- console.log('Now moving the figma2html files...');
21
+ const filename = file.replace(".zip", "")
22
+ return (filename);
34
23
 
35
- // check if there's app/templates/figma2html-output directory
36
- const templatesPath = 'app/templates/figma2html-output';
24
+ } catch (err) {
25
+ console.log(err)
26
+ }
27
+ }
28
+
29
+ const makeDirectory = path => {
37
30
  try {
38
- fs.accessSync(templatesPath);
31
+ fs.accessSync(path);
32
+ return (path);
39
33
  } catch (err) {
40
- fs.mkdirSync(templatesPath, err => {
34
+ fs.mkdirSync(path, err => {
41
35
  if (err) {
42
36
  console.log(err);
43
37
  } else {
44
- console.log('created figma2html-output directory!');
38
+ console.log(`created new ${path} directory!`);
39
+ return (path);
45
40
  }
46
- });
47
- } finally {
48
- moveHtml(filename);
41
+ })
49
42
  }
43
+ }
50
44
 
51
- // check if there's app/assets/figma2html directory
52
- const assetsPath = 'app/assets/figma2html/';
45
+ const makeHigherDirectories = filename => {
46
+ // check and make directries
47
+ try {
48
+ makeDirectory('app/templates/figma2html-output')
49
+ makeDirectory('app/assets/figma2html/')
50
+
51
+ return (filename);
52
+
53
+ } catch (err) {
54
+ console.log(err)
55
+ }
56
+ };
53
57
 
58
+ const makeLowerDirectories = filename => {
59
+ // check and make directries
54
60
  try {
55
- fs.accessSync(assetsPath);
56
- console.log('figma2html directory already exists!');
61
+ makeDirectory('app/assets/figma2html/' + filename);
62
+
63
+ return (filename);
64
+
57
65
  } catch (err) {
58
- fs.mkdirSync(assetsPath, err => {
59
- if (err) {
60
- console.log(err);
61
- } else {
62
- console.log('created new figma2html directory!');
66
+ console.log(err)
67
+ }
68
+ };
69
+
70
+
71
+ const moveImages = filename => {
72
+ // move the image files in the app/assets/figma2html/FILENAME directory
73
+ const imagesPath = 'workspace/figma2html-exports/assets/figma2html/' + filename;
74
+ fs.readdir(imagesPath, (err, images) => {
75
+ images.forEach((image, index) => {
76
+ console.log('moving ' + filename + ", " + image + '...');
77
+ fs.renameSync(
78
+ imagesPath + '/' + image,
79
+ 'app/assets/figma2html/' + filename + '/' + image
80
+ );
81
+ if (index == images.length - 1) {
82
+ return (filename);
63
83
  }
64
84
  });
65
- } finally {
66
- // create app/assets/figma2html/FILENAME directory
67
- try {
68
- fs.accessSync(assetsPath + filename);
69
- console.log('app/assets/figma2html/' + filename + ' already exists!');
70
- } catch (err) {
71
- fs.mkdirSync(assetsPath + filename, err => {
72
- if (err) {
73
- console.log(err);
74
- } else {
75
- console.log('created figma2html/FILENAME directory!');
76
- }
77
- });
78
- }
79
- moveImages(filename);
80
- }
85
+ });
81
86
  };
82
87
 
83
- const extractZip = async file => {
84
- // extract the zip file
88
+ const moveHtmlFiles = filename => {
85
89
  try {
86
- console.log('Unzipping ' + colors.magentaBright(file) + '...');
87
- await extract(
88
- resolve('workspace/' + file),
89
- // save the extracted zip file in the workspace directory
90
- { dir: resolve('workspace') }
90
+ // move the .html file in the app/templates directory
91
+ fs.rename(
92
+ 'workspace/figma2html-exports/' + filename + '.html',
93
+ 'app/templates/figma2html-output/' + filename + '.html'
91
94
  );
92
- console.log(colors.magentaBright(file) + ' Extraction completed');
95
+
96
+ return (filename)
93
97
  } catch (err) {
94
- // handle any errors
95
- } finally {
96
- // get the file name
97
- const filename = file.replace('.zip', '');
98
- // then move files
99
- moveFiles(filename);
98
+ console.log(err)
100
99
  }
101
100
  };
102
101
 
103
- module.exports = () => {
102
+ const organizeFiles = async file => {
103
+ try {
104
+ // extract zip file
105
+ const extractedZip = await extractZip(file);
106
+ // make directories
107
+ const madeHigherDirectories = await makeHigherDirectories(extractedZip);
108
+ const madeLowerDirectories = await makeLowerDirectories(madeHigherDirectories)
109
+ // move images
110
+ await moveImages(madeLowerDirectories);
111
+ // move html files
112
+ await moveHtmlFiles(madeLowerDirectories);
113
+
114
+ } catch (err) {
115
+ console.log(err)
116
+ }
117
+ }
118
+
119
+ // main function
120
+ module.exports = async () => {
104
121
  // check if a zip file exists in the workspace directory
105
- fs.readdir('workspace', (err, files) => {
122
+ fs.readdir('workspace/figma2html-exports', (err, files) => {
106
123
  files.forEach(file => {
107
- if (file.includes('assets')) {
108
- // remove old assets files
109
- fs.rmSync(file, { recursive: true, force: true });
110
- } else if (file.includes('.zip')) {
111
- // extract the zip file
112
- extractZip(file);
124
+ if (file.includes('.zip')) {
125
+ organizeFiles(file);
113
126
  }
114
127
  });
115
128
  });
116
129
  };
130
+
@@ -37,7 +37,8 @@
37
37
 
38
38
  {# add name of your figma2html file here #}
39
39
  {# {% set figma2html = "" %}
40
- {% include "figma2html-output/" + figma2html + ".html" %} #}
40
+ {% include "figma2html-output/" + figma2html + ".html" %}
41
+ {% include 'includes/figma2html-config.html' %}#}
41
42
 
42
43
  {# data-source and data-credit are also used in the CMS #}
43
44
  <ul class="graphic-footer">