Code Monkey home page Code Monkey logo

Comments (18)

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024 1

So, now I do have yarn installed globally, but I can also npm install your plugin, correct?

You could, yes, but generally it's not recommended to mix npm and yarn because they generate different .lock files (yarn.lock vs. package-lock.json), and since lockfiles are usually gitignored, whichever one isn't gitignored would show up as an untracked file in git.

And what about that cross-env? Do you have to implement it?

If you'd like to, you could fix this and put up a pull request, or I could fix it myself. Here are the steps:

  1. Fork this repository to your personal GitHub account.
  2. Clone the fork onto your machine with git.
  3. Create a new branch off of master (maybe name the branch cross-env).
  4. Do yarn add -D cross-env to install cross-env as a dev-dependency.
  5. Update this line in package.json:

"dev": "ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental",

-"dev": "ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental",
+"dev": "cross-env ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental",
  1. Add changes to git, commit, push up, and open a PR.
  2. You can also test if yarn dev works at this point.

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024 1

I'd like to try to fix myself and put up a pull request, just to learn something new. But it's my first time doing this and I need a few hours when I'm home. I'll follow your instructions, then.
One more thing, just to be sure: I will have to install your plugin into another private repo of a website. In there I've always used npm install. If I understood correctly, I better continue with npm install over there once this will be fixed? Just like any other Eleventy plugin I've already npm installed? Thanks!

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024 1

I'd like to try to fix myself and put up a pull request, just to learn something new. But it's my first time doing this and I need a few hours when I'm home. I'll follow your instructions, then.

Sounds good!

If I understood correctly, I better continue with npm install over there once this will be fixed? Just like any other Eleventy plugin I've already npm installed? Thanks!

Yes, if your project uses npm, you don't have to worry about whether X package uses yarn or some other package manager. You can continue to use npm.

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024 1

I think I succeeded. PR opened, and also:

PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo> yarn dev
yarn run v1.22.19
$ cross-env ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental
[11ty] Writing _site/index.html from ./demo/index.md (njk)
[11ty] Wrote 1 file in 0.24 seconds (v1.0.2)
[11ty] Watching…
[Browsersync] Access URLs:
 ----------------------------------
    Local: http://localhost:8080
 External: http://192.168.1.11:8080
 ----------------------------------
[Browsersync] Serving files from: _site

Thank you Aleksandr!

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024 1

All good, I opened a PR here: #2. Edit: Merged! Thanks again.

Looks like something may have changed with Eleventy 2.0's module resolution 😞 I'll take a look and see what I can figure out.

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024 1

Apparently this was an issue on my end! lodash/escape should've been lodash.escape. But what's weird is how I was only able to reproduce the issue on @11ty/[email protected], but my import path for lodash.escape was clearly wrong (lodash/escape). Maybe @11ty/eleventy didn't do any validation on import paths? Not sure how it was working 🀷 In any case, it should work now. Going to do a release and hope that fixes it.

Edit: Released in 0.0.2, upgrade when you get a chance and let me know if it works on your end now. Sorry for the trouble!

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024 1

No problem! Since we fixed this particular bug, I'm going to close the issue. Feel free to open another issue if you run into other problems.

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024

Thanks! I'll take a look later today and see if I can track down the cause of the issue. In the meantime, can you try cloning this project and running the demo folder (yarn followed by yarn dev) to see if you run into the same issue here?

Also, are you trying this through cmd/powershell or through WSL?

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024
PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo> yarn
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 38.10s.
PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo> yarn dev
yarn run v1.22.19
$ ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental
"ELEVENTY_ENV" non Γ¨ riconosciuto come comando interno o esterno,
 un programma eseguibile o un file batch.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo>

"ELEVENTY_ENV" not recognized as an internal or external command, an executable program, or a batch file (translated from Italian).
As you can see I'm an absolute beginner here. Could it be that I was trying to install your plugin with npm? npm install eleventy-plugin-code-demo.
Also I do not understand that error Command failed with exit code 1

I'm using VS Code terminal - which is Powershell, I guess.

Also, before, I do not remember at which point now, I had to npm install eslint and reopen the workspace

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024

Ah, my bad, I should be using cross-env here so that the script works on Windows terminals too. ENVIRONMENT_VARIABLE=value is the Unix format for setting environment variables in the context of an executing script, but it's not recognized by Windows, so it errors when you run yarn dev.

I'm using VS Code terminal - which is Powershell, I guess.

Yup, you're using PowerShell (the PS at the start of your output indicates this).

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024

Hahaha... that PS was a mistery to me. So, now I do have yarn installed globally, but I can also npm install your plugin, correct? And what about that cross-env? Do you have to implement it?

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024

@rocc-o Congrats! Looks like the PR is in your fork: rocc-o#1. You'll want to head over to the Pull Requests tab on my repo instead (https://github.com/AleksandrHovhannisyan/eleventy-plugin-code-demo/pulls) and open a PR from your fork into master (sorry, didn't clarify that step). Let me know if you need help. But otherwise, the code looks good!

Regarding the output: Great! It ran correctly. That leads me to suspect that it's either:

  1. An issue with Eleventy 2.0, or
  2. Something in your .eleventy.js config.

One thing you could do to rule out the Eleventy version: In your local clone of this plugin, run yarn add -D @11ty/[email protected] to install Eleventy 2.0.0 (the plugin was originally tested on v1.0.2). Then re-run yarn dev when that finishes and see if you get the same error that you got on your site. If you don't get an error, could you please share your .eleventy.js here (if you're okay with that)?

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024

So, I went over to your original repositories Pull Requests tab, where I should see, I suppose, something like a suggestion from GitHub to create a pull request from my new branch. But I see only "There aren’t any open pull requests". Sure I'm doing something wrong.

Anyway, bad news: it seems to have something to do with Eleventy 2.0, maybe, as far as I understand

PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo> yarn add -D @11ty/[email protected]
yarn add v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Saved lockfile.
success Saved 35 new dependencies.
info Direct dependencies
└─ @11ty/[email protected]
info All dependencies
β”œβ”€ @11ty/[email protected]
β”œβ”€ @11ty/[email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
β”œβ”€ [email protected]
└─ [email protected]
Done in 12.24s.
PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo> yarn dev
yarn run v1.22.19
$ cross-env ELEVENTY_ENV=development npx @11ty/eleventy --serve --incremental
[11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
[11ty] 1. Error in your Eleventy config file '.eleventy.js'. You may need to run `npm install`. (via EleventyConfigError)
[11ty] 2. Cannot find module 'lodash/escape'
[11ty] Require stack:
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\src\utils.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\src\index.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\.eleventy.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\Util\Require.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\TemplateConfig.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\EleventyExtensionMap.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\TemplateData.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\Eleventy.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\cmd.js (via Error)
[11ty]
[11ty] Original error stack trace: Error: Cannot find module 'lodash/escape'
[11ty] Require stack:
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\src\utils.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\src\index.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\.eleventy.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\Util\Require.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\TemplateConfig.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\EleventyExtensionMap.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\TemplateData.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\src\Eleventy.js
[11ty] - C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\node_modules\@11ty\eleventy\cmd.js
[11ty]     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
[11ty]     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
[11ty]     at Module.require (node:internal/modules/cjs/loader:1005:19)
[11ty]     at require (node:internal/modules/cjs/helpers:102:18)
[11ty]     at Object.<anonymous> (C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo\src\utils.js:1:16)
[11ty]     at Module._compile (node:internal/modules/cjs/loader:1101:14)
[11ty]     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
[11ty]     at Module.load (node:internal/modules/cjs/loader:981:32)
[11ty]     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
[11ty]     at Module.require (node:internal/modules/cjs/loader:1005:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\Users\ricca\OneDrive\Documenti\Websites\eleventy-plugin-code-demo>

And here's my .eleventy,js

// (**) https://github.com/gregives/eleventy-critical-css
//const criticalCss = require("eleventy-critical-css");

// (*) https://www.11ty.dev/docs/config/#transforms-example-minify-html-output
const htmlmin = require("html-minifier");

// (***) https://www.11ty.dev/docs/plugins/rss/
const pluginRss = require("@11ty/eleventy-plugin-rss");

// https://www.11ty.dev/docs/languages/webc/#global-no-import-components
//const pluginWebc = require("@11ty/eleventy-plugin-webc");

// In order to render webc inside .njk templates
// https://www.11ty.dev/docs/languages/webc/#use-the-render-plugin
// https://www.11ty.dev/docs/plugins/render/
//const { EleventyRenderPlugin } = require("@11ty/eleventy");






// remove me -- upgrade helper plugin (for v.2)
//const UpgradeHelper = require("@11ty/eleventy-upgrade-help");






module.exports = function (eleventyConfig) {



// Terser javascript minifier (for injected js in _pages-layout.njk + _no-hero-pages-layout.njk)
// https://www.11ty.dev/docs/quicktips/inline-js/
const { minify } = require("terser");
eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (
  code,
  callback
) {
  try {
    const minified = await minify(code);
    callback(null, minified.code);
  } catch (err) {
    console.error("Terser error: ", err);
    // Fail gracefully.
    callback(null, code);
  }
});
// END of Terser  



// for "/sights/sights.11tydata.js" and "/sights/sights.11tydata.js"
// https://github.com/11ty/eleventy/issues/2048
  eleventyConfig.setDataDeepMerge(true);


  // Articles: the same logic as custom collection, except for as a filter; so it can pass a custom collection.
  // https://github.com/rocc-o/raw-test-git/pull/2/files
  const now = Date.now();
  const livePosts = (post) => post.date <= now;

  eleventyConfig.addFilter("tagsList", (arr = []) => {
    const tagsSet = new Set();
    arr.forEach((item) => item.data.tags?.forEach((tag) => tagsSet.add(tag)));
    return [...tagsSet].sort((b, a) => b.localeCompare(a));
  });

  eleventyConfig.addFilter("inspect", require("util").inspect);

  // Articles SIGHTS - custom collections
  eleventyConfig.addCollection("sights", (collection) => {
    const posts = collection.getFilteredByGlob("./sights/*.njk");
    return [...posts].filter(livePosts).reverse();
  });

  // Articles SOUNDS - custom collections
  eleventyConfig.addCollection("sounds", (collection) => {
    const posts = collection.getFilteredByGlob("./sounds/*.njk");
    return [...posts].filter(livePosts).reverse();
  });


  // generate list of tags for Sights
  eleventyConfig.addCollection("sightsTagsList", (collection) => {
    const tagsListFilter = eleventyConfig.getFilter("tagsList");
    const items = collection
      .getFilteredByGlob("./sights/*.njk")
      .filter(livePosts);
    return tagsListFilter(items);
  });

  // generate list of tags for Sounds
  eleventyConfig.addCollection("soundsTagsList", (collection) => {
    const tagsListFilter = eleventyConfig.getFilter("tagsList");
    const items = collection
      .getFilteredByGlob("./sounds/*.njk")
      .filter(livePosts);
    return tagsListFilter(items);
  });


    // for Latest Articles on homepage
    // this is for index.njk throwing errors saying there is not a "head" filter
      eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
        if (idx < 0) {
          return arr.slice(idx);
        }
        return arr.slice(0, idx);
      });
 

    // Custom audio player -- filter for _data/sounds.json
    // https://github.com/11ty/eleventy/issues/2746#issuecomment-1383212962
    // https://github.com/pdehaan/11ty-2746
      eleventyConfig.addFilter("getSound", (sounds = [], label = "") => {
      // console.log({sounds, label});
      const sound = sounds.find(s => s.key === label.toString());
      if (sound) {
        return sound;
      }
      throw new Error(`Unknown sound key: "${label}"`);
    });


   // Contributors
   // https://github.com/cfjedimaster/eleventy-demos/tree/master/multiauthor
   // https://www.raymondcamden.com/2020/08/24/supporting-multiple-authors-in-an-eleventy-blog
   eleventyConfig.addFilter("getContributor", (contributors,label) => {
 		let contributor = contributors.filter(a => a.key === label)[0];
 		return contributor;
 	});

 	eleventyConfig.addFilter("getPostsByContributor", (posts,contributor) => {
 		return posts.filter(a => a.data.contributor === contributor);
 	});


// create custom collections for each contributor
// in order to paginate each contributor's articles on his contributor's page
const contributors = require("./_data/contributors.json");
for (const contributor of contributors) {
  eleventyConfig.addCollection(`contributor_${contributor.key}`, (collectionApi) => {
    return collectionApi.getFilteredByTag("post")
      .filter(post => post.data.contributor === contributor.key)
      .sort((a, b) => Date.parse(b.date) - Date.parse(a.date));
  });
}


  // Add filter to meta_title for Search on static_search.njk
  eleventyConfig.addFilter("squash", require("./lib/filters/squash.js") );


  // (***) https://www.11ty.dev/docs/plugins/rss/
  eleventyConfig.addPlugin(pluginRss);


  // https://www.11ty.dev/docs/languages/webc/#global-no-import-components
  //eleventyConfig.addPlugin(pluginWebc, {
		// Glob to find no-import global components
    // This path is relative to the project-root!
		// (The default changed from `false` in Eleventy WebC v0.7.0)
	//components: "_components/**/*.webc",
	//}); 

  
  // In order to render webc inside .njk templates
  // https://www.11ty.dev/docs/languages/webc/#use-the-render-plugin
  // https://www.11ty.dev/docs/plugins/render/
  //eleventyConfig.addPlugin(EleventyRenderPlugin);






  // remove me -- upgrade helper plugin (for v.2)
  // If you have other `addPlugin` calls, it’s important that UpgradeHelper is added last.
  //eleventyConfig.addPlugin(UpgradeHelper);






  // Social Share Links -- see: _includes/partials/components/social-share.njk
  // and Canonical URL metatags in _includes/head.njk and _includes/head-below-pages.njk
  const site = require('./_data/site.js');

  /**
   * Prefixes the given URL with the site's base URL.
   * @param {string} url
   */
  const toAbsoluteUrl = (url) => {
    return new URL(url, site.baseUrl).href;
  }
  
  eleventyConfig.addFilter('toAbsoluteUrl', toAbsoluteUrl);
  // end of Social Share Links and Canonical URL metatags


// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster)
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addPassthroughCopy('apple-touch-icon.png');
eleventyConfig.addPassthroughCopy('favicon.ico');
eleventyConfig.addPassthroughCopy('icon-192.png');
eleventyConfig.addPassthroughCopy('icon-512.png');
eleventyConfig.addPassthroughCopy('icon.svg');
eleventyConfig.addPassthroughCopy('manifest.webmanifest.webmanifest');
eleventyConfig.addPassthroughCopy('maskable_icon_x192.png');
eleventyConfig.addPassthroughCopy('maskable_icon_x512.png');
eleventyConfig.addPassthroughCopy('service-worker.js');
eleventyConfig.addPassthroughCopy('robots.txt');
// https://jonkuperman.com/custom-headers-eleventy-cloudflare-pages/
// https://www.seancdavis.com/posts/netlify-redirects-headers-with-eleventy/
// https://developers.cloudflare.com/pages/platform/headers#prevent-your-pagesdev-deployments-showing-in-search-results
eleventyConfig.addPassthroughCopy({ static: "/" });


// (**) https://github.com/gregives/eleventy-critical-css
// When changing configuration - dimensions etc - after re-run from beginning npx @11ty/eleventy --serve
// for modifications to take effect
// If I set height/width for a specifici viewport - eg.iPhone 12 Pro Max - it will inline css @media rules upto that specific viewport
// including the ones below, and discharge the ones above - eg. iPad Pro 12 and above.
//eleventyConfig.addPlugin(criticalCss, {
//  dimensions: [
//    {
//      height: 1440, //iMac 27 inch
//      width: 2560,
//    },
//  ],
//});
// dimensions: resolution 2560x1440 only, includes also all resolutions below, fron mobiles upto desktop 2560x1440
// "All you have to do is to specify the largest dimension you want it to work for, and it will work for all lower dimensions":
// https://github.com/addyosmani/critical/pull/66#issuecomment-75395350
// END


// (*) https://www.11ty.dev/docs/config/#transforms-example-minify-html-output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if( outputPath && outputPath.endsWith(".html") ) {
  let minified = htmlmin.minify(content, {
    useShortDoctype: true,
    removeComments: true,
    collapseWhitespace: true
  });
  return minified;
}

return content;
});
// END


// format dates on SIGHTS and SOUNDS Articles
const dateformat = require("./lib/filters/dateformat");
eleventyConfig.addFilter("datefriendly", dateformat.friendly);
eleventyConfig.addFilter("dateymd", dateformat.ymd);


// "return" in order to keep the previously entered configuration values
// taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js
return {
  // Control which files Eleventy will process
  // e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ["md", "njk", "html", "liquid"],

// added
  passthroughFileCopy: true,

  // -----------------------------------------------------------------
  // If your site deploys to a subdirectory, change `pathPrefix`.
  // Don’t worry about leading and trailing slashes, we normalize these.

  // If you don’t have a subdirectory, use "" or "/" (they do the same thing)
  // This is only used for link URLs (it does not affect your file structure)
  // Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/

  // You can also pass this in on the command line using `--pathprefix`

  // Optional (default is shown)
  pathPrefix: "/",
  // -----------------------------------------------------------------

  // Pre-process *.md files with: (default: `liquid`)
  markdownTemplateEngine: "njk",

  // Pre-process *.html files with: (default: `liquid`)
  htmlTemplateEngine: "njk",

  // Opt-out of pre-processing global data JSON files: (default: `liquid`)
  dataTemplateEngine: false,

  // These are all optional (defaults are shown):
  dir: {
    input: ".",
    includes: "_includes",
    data: "_data",
    output: "_site",
  },
};
};

I'll be back tomorrow in the afternoon (now it's 9:30pm here in Italy). Thanks for now Aleksandr.

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024

It errors on my end as well:

[11ty] Original error stack trace: Error: Cannot find module 'lodash/escape'
[11ty] Require stack:
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/src/utils.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/src/index.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/.eleventy.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/node_modules/@11ty/eleventy/src/Util/Require.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/node_modules/@11ty/eleventy/src/TemplateConfig.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/node_modules/@11ty/eleventy/src/EleventyExtensionMap.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/node_modules/@11ty/eleventy/src/TemplateData.js
[11ty] - /home/aleks/dev/eleventy-plugin-code-demo/node_modules/@11ty/eleventy/src/Eleventy.js

Looks like the stack trace involves 11ty/eleventy/src/Util/Require.js. Gonna take a closer look and see if I can create a minimal repro sandbox. Then I'll file an issue either with eleventy or in the eleventy-utils repo.

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024

Great!
So, I have successfully installed your plugin. But I have an error with title required for accessibility. I'm using Nunjucks variable for title. Could this be the reason?

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering njk template ./sounds/trane-the-lost-reel.njk (via TemplateContentRenderError)
[11ty] 2. (./sounds/trane-the-lost-reel.njk)
[11ty]   Template render error: (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\_includes\partials\components\articles-audio-iframe.njk)
[11ty]   EleventyShortcodeError: Error with Nunjucks paired shortcode `srcdoc` (via Template render error)
[11ty] 3. srcdoc: you must provide a non-empty title for the iframe. (via Template render error)
[11ty] 
[11ty] Original error stack trace: Error: srcdoc: you must provide a non-empty title for the iframe.
[11ty]     at Object.codeDemoShortcode (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\eleventy-plugin-code-demo\src\utils.js:46:13)
[11ty]     at Object.<anonymous> (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\@11ty\eleventy\src\BenchmarkGroup.js:32:26)
[11ty]     at C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\@11ty\eleventy\src\Engines\Nunjucks.js:302:31
[11ty]     at eval (eval at _compile (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:20:1)
[11ty]     at PairedShortcodeFunction.run (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\@11ty\eleventy\src\Engines\Nunjucks.js:266:9)  
[11ty]     at Template.root [as rootRenderFunc] (eval at _compile (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:11:34)
[11ty]     at Template.render (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\nunjucks\src\environment.js:552:10)
[11ty]     at eval (eval at _compile (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:99:10)
[11ty]     at fn (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\a-sync-waterfall\index.js:26:24)
[11ty]     at C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims.github.io\node_modules\a-sync-waterfall\index.js:66:22
[11ty] Copied 11 files / Wrote 0 files in 0.54 seconds (v2.0.0)
//.eleventy.js
// Please note I have uncommented iframeAttributes as I do not need them

eleventyConfig.addPlugin(EleventyPluginCodeDemo, {
  // Use any shortcode name you want
  name: 'srcdoc',
  /* Render whatever document structure you want. The HTML, CSS, and JS parsed 
  from the shortcode's body are supplied to this function as an argument, so 
  you can position them wherever you want, or add class names or data-attributes to html/body */
  renderDocument: ({ html, css, js }) => `
  <!DOCTYPE html>
  <html>
    <head>
      <style>${css}</style>
    </head>
    <body>
      ${html}
      <script>${js}</script>
    </body>
  </html>`,
  // key-value pairs for HTML attributes; these are applied to all code previews
  iframeAttributes: {
  //  height: '300',
  //  style: 'width: 100%;',
  //  frameborder: '0',
  },
});
{# _includes/partials/components/articles-audio-iframe.njk
    I'm using double quotes inside srcdoc now - that was the purpose in order to minify html output
 #}

{% srcdoc %}
```html

    <iframe 
    title="{{ title_alt_text }}" 
    allowfullscreen 
    loading="lazy" 
          srcdoc="<style> body, .full { width: 100%; height: 100%; margin: 0; position: absolute; display: flex; justify-content: center; object-fit: contain } </style>
          <a href="{{ audio_url }}" class="full">

            <picture class="full">

            <source
            media="(max-width: 511px)"
            srcset="
            /assets/img/audio-player/portrait-544.webp 544w,
            /assets/img/audio-player/portrait-652.webp 652w,
            /assets/img/audio-player/portrait-728.webp 728w"
            type="image/webp">

            <source
            media="(min-width: 512px)"
            srcset="
            /assets/img/audio-player/landscape-680.webp 680w,
            /assets/img/audio-player/landscape-1360.webp 1360w"
            type="image/webp">

            <source
            media="(max-width: 511px)"
            srcset="
            /assets/img/audio-player/portrait-544.jpg 544w,
            /assets/img/audio-player/portrait-652.jpg 652w,
            /assets/img/audio-player/portrait-728.jpg 728w"
            >

            <source
            media="(min-width: 512px)"
            srcset="
            /assets/img/audio-player/landscape-680.jpg 680w,
            /assets/img/audio-player/landscape-1360.jpg 1360w"
            >

            <img src="/assets/img/audio-player/landscape-680.jpg"
            loading="lazy" width="680" height="160" alt="{{ title_alt_text }}" title="Click to load audio" class="full">

            </picture>

          </a>"
    ></iframe>

{#```
{% endsrcdoc %} #}

{# I have to uncomment the above two lines here as they are in conflict with GitHub editor  #}

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024

Without Nunjucks variable, just with plain title I get: 3. srcdoc: you must provide a non-empty title for the iframe. (via Template render error)

from eleventy-plugin-code-demo.

AleksandrHovhannisyan avatar AleksandrHovhannisyan commented on September 24, 2024

@rocc-o You'll want to do:

{% srcdoc 'Descriptive title for your iframe' %}

See the docs in the README for more examples.

from eleventy-plugin-code-demo.

rocc-o avatar rocc-o commented on September 24, 2024

Yes, I just realized in this very moment. Now it works. I'm gonna play a little with this beatiful plugin today and I'll be back to you. Thanks so much for now, Aleksandr.

from eleventy-plugin-code-demo.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.