@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 +1 -1
- package/templates/__common__/app/styles/_typography-queso.scss +9 -0
- package/templates/__common__/app/styles/_typography.scss +9 -0
- package/templates/__common__/app/templates/includes/figma2html-config.html +26 -0
- package/templates/__common__/config/tasks/parse-figma2html.js +91 -77
- package/templates/graphic/app/templates/graphic-static.html +2 -1
package/package.json
CHANGED
|
@@ -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
|
|
11
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
33
|
-
|
|
21
|
+
const filename = file.replace(".zip", "")
|
|
22
|
+
return (filename);
|
|
34
23
|
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.log(err)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const makeDirectory = path => {
|
|
37
30
|
try {
|
|
38
|
-
fs.accessSync(
|
|
31
|
+
fs.accessSync(path);
|
|
32
|
+
return (path);
|
|
39
33
|
} catch (err) {
|
|
40
|
-
fs.mkdirSync(
|
|
34
|
+
fs.mkdirSync(path, err => {
|
|
41
35
|
if (err) {
|
|
42
36
|
console.log(err);
|
|
43
37
|
} else {
|
|
44
|
-
console.log(
|
|
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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
56
|
-
|
|
61
|
+
makeDirectory('app/assets/figma2html/' + filename);
|
|
62
|
+
|
|
63
|
+
return (filename);
|
|
64
|
+
|
|
57
65
|
} catch (err) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
}
|
|
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
|
|
84
|
-
// extract the zip file
|
|
88
|
+
const moveHtmlFiles = filename => {
|
|
85
89
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
95
|
+
|
|
96
|
+
return (filename)
|
|
93
97
|
} catch (err) {
|
|
94
|
-
|
|
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
|
-
|
|
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('
|
|
108
|
-
|
|
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">
|