@daz4126/swifty 1.4.0 → 1.5.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.
Files changed (4) hide show
  1. package/README.md +19 -0
  2. package/init.js +1 -1
  3. package/package.json +1 -1
  4. package/swifty.js +17 -11
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Swifty
2
+ ## Super Speedy Static Site Generator
3
+
4
+ Swifty is the next generation of static site generator.
5
+
6
+ It uses the power of Turbo and morphing to build sites that are blazingly fast.
7
+
8
+ It also uses convention over configuration to make is super simple to build sites.
9
+
10
+ ## Quickstart
11
+
12
+ 1. `npm install @daz4126/swifty`
13
+ 2. `npx swifty init`
14
+ 3. `npx swifty build` to build the site
15
+ 4. Edit the `template.html` file to match your default layout
16
+ 5. Change the `sitename` in `config.yaml`
17
+ 6. Add some markdown files to the 'pages' directory
18
+ 7. `npx swifty start` to rebuild and start the server
19
+ 8. Visit [http://localhost:3000] to see your site
package/init.js CHANGED
@@ -17,7 +17,7 @@ const structure = {
17
17
  "css/": null,
18
18
  "js/": null,
19
19
  "images/": null,
20
- "config.yaml": "site_name: My Swifty Site",
20
+ "config.yaml": "sitename: My Swifty Site",
21
21
  "template.html": `<!DOCTYPE html>
22
22
  <html lang="en">
23
23
  <head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/swifty",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
package/swifty.js CHANGED
@@ -107,20 +107,25 @@ async function optimizeImages() {
107
107
  await Promise.all(files.map(async (file) => {
108
108
  const filePath = path.join(images_folder, file);
109
109
  const ext = path.extname(file).toLowerCase();
110
-
110
+
111
111
  if (!IMAGE_EXTENSIONS.includes(ext)) return;
112
-
112
+
113
113
  const optimizedPath = path.join(images_folder, `${path.basename(file, ext)}.webp`);
114
-
115
- // Ensure we are not overwriting the same file
114
+
116
115
  if (filePath !== optimizedPath) {
117
- await sharp(filePath)
118
- .resize({ width: defaultConfig.max_image_size || 800 })
116
+ const image = sharp(filePath);
117
+ const metadata = await image.metadata();
118
+ const originalWidth = metadata.width || 0;
119
+ const maxWidth = defaultConfig.max_image_size || 800;
120
+ const resizeWidth = Math.min(originalWidth, maxWidth);
121
+
122
+ await image
123
+ .resize({ width: resizeWidth })
119
124
  .toFormat('webp', { quality: 80 })
120
125
  .toFile(optimizedPath);
121
-
126
+
122
127
  await fs.unlink(filePath);
123
-
128
+
124
129
  console.log(`Optimized ${file} -> ${optimizedPath}`);
125
130
  }
126
131
  }));
@@ -135,6 +140,7 @@ const generateAssetImports = async (dir, tagTemplate, validExts) => {
135
140
  const files = await fs.readdir(dir);
136
141
  return files
137
142
  .filter(file => validExts.includes(path.extname(file).toLowerCase()))
143
+ .sort()
138
144
  .map(file => tagTemplate(file))
139
145
  .join('\n');
140
146
  };
@@ -344,7 +350,7 @@ const render = async page => {
344
350
  // Function to read and render the index template
345
351
  const renderIndexTemplate = async (content, config) => {
346
352
  // Read the template from pages folder
347
- const templatePath = path.join(__dirname, 'template.html');
353
+ const templatePath = path.join(baseDir, 'template.html');
348
354
  let templateContent = await fs.readFile(templatePath, 'utf-8');
349
355
 
350
356
  // Add the meta tag for Turbo refresh method
@@ -492,5 +498,5 @@ const generateSite = async () => {
492
498
 
493
499
  // Run the site generation process
494
500
  generateSite()
495
- .then(() => console.log('Site generated successfully!'))
496
- .catch(err => console.error('Error generating site:', err));
501
+ .then(() => console.log('🚀 Site generated successfully! 🥳'))
502
+ .catch(err => console.error('🛑 Error generating site:', err));