oleeskild / obsidian-digital-garden

MIT License
1.32k stars 122 forks source link

It should be easier to modify the template, without redoing work when updating it later #119

Closed ksdavidc closed 1 year ago

ksdavidc commented 1 year ago

1st. Go slow when talking to me. I am sometimes out of my depth as far as some of this tech goes, 11ty I know nothing about, for example. I have a passable understanding of Github and obsidian, html, etc..

I tried the update function for the first time. I got the link to the PR on github and went to Netlify and found the deploy preview link and got the error report given in full below.

It appears that these are the relevant lines, as the first of these was marked in red:

8:13:47 AM: [11ty] Problem writing Eleventy templates: (more in DEBUG output)
8:13:47 AM: [11ty] > Cannot find module '../helpers/constants'

Aside from that I don't know what it all means.

One thing I know is I am using version 2.20.0 of the plugin. I have not updated since I have it working and don't want to mess things up... I am not sure if it is safe to update the version of the plugin, and if that should be done before trying to update the template. Can I update the plugin without affecting the site? Or do I update the template first, then the plugin?

I closed the PR and deleted the branch. I want to try again, but I am not sure how to proceed, safely.


8:13:20 AM: build-image version: 4c0c1cadee6a31c9bb8d824514030009c4c05c6a (focal)
8:13:20 AM: build-image tag: v4.15.0
8:13:20 AM: buildbot version: cc0c986a947e274d444f48f63f797a5d01f2a89a
8:13:20 AM: Fetching cached dependencies
8:13:20 AM: Starting to download cache of 260.1MB
8:13:23 AM: Finished downloading cache in 3.064911719s
8:13:23 AM: Starting to extract cache
8:13:25 AM: Finished extracting cache in 2.467972694s
8:13:25 AM: Finished fetching cache in 5.587003307s
8:13:25 AM: Starting to prepare the repo for build
8:13:26 AM: Preparing Git Reference pull/1/head
8:13:27 AM: Parsing package.json dependencies
8:13:28 AM: Section completed: initializing
8:13:28 AM: Starting build script
8:13:28 AM: Installing dependencies
8:13:28 AM: Python version set to 2.7
8:13:28 AM: Started restoring cached node version
8:13:30 AM: Finished restoring cached node version
8:13:30 AM: v16.18.1 is already installed.
8:13:30 AM: Now using node v16.18.1 (npm v8.19.2)
8:13:31 AM: Enabling node corepack
8:13:31 AM: Started restoring cached build plugins
8:13:31 AM: Finished restoring cached build plugins
8:13:31 AM: Attempting ruby version 2.7.2, read from environment
8:13:31 AM: Using ruby version 2.7.2
8:13:32 AM: Using PHP version 8.0
8:13:32 AM: No npm workspaces detected
8:13:32 AM: Started restoring cached node modules
8:13:32 AM: Finished restoring cached node modules
8:13:32 AM: Installing NPM modules using NPM version 8.19.2
8:13:34 AM: npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
8:13:37 AM: added 30 packages, removed 62 packages, changed 53 packages, and audited 605 packages in 5s
8:13:37 AM: 71 packages are looking for funding
8:13:37 AM:   run `npm fund` for details
8:13:37 AM: 12 vulnerabilities (5 moderate, 6 high, 1 critical)
8:13:37 AM: To address issues that do not require attention, run:
8:13:37 AM:   npm audit fix
8:13:37 AM: To address all issues possible (including breaking changes), run:
8:13:37 AM:   npm audit fix --force
8:13:37 AM: Some issues need review, and may require choosing
8:13:37 AM: a different dependency.
8:13:37 AM: Run `npm audit` for details.
8:13:37 AM: NPM modules installed
8:13:37 AM: Creating package sha
8:13:38 AM: Started restoring cached go cache
8:13:38 AM: Finished restoring cached go cache
8:13:38 AM: Installing Go version 1.17 (requested 1.17)
8:13:43 AM: unset GOOS;
8:13:43 AM: unset GOARCH;
8:13:43 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
8:13:43 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
8:13:43 AM: go version >&2;
8:13:43 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
8:13:43 AM: go version go1.17 linux/amd64
8:13:43 AM: Detected 1 framework(s)
8:13:43 AM: "eleventy" at version "1.0.0"
8:13:43 AM: Installing missing commands
8:13:43 AM: Verify run directory
8:13:45 AM: ​
8:13:45 AM: ────────────────────────────────────────────────────────────────
8:13:45 AM:   Netlify Build                                                 
8:13:45 AM: ────────────────────────────────────────────────────────────────
8:13:45 AM: ​
8:13:45 AM: ❯ Version
8:13:45 AM:   @netlify/build 29.0.1
8:13:45 AM: ​
8:13:45 AM: ❯ Flags
8:13:45 AM:   baseRelDir: true
8:13:45 AM:   buildId: 63911e0ee5023e0008c7e5f3
8:13:45 AM:   deployId: 63911e0ee5023e0008c7e5f5
8:13:45 AM: ​
8:13:45 AM: ❯ Current directory
8:13:45 AM:   /opt/build/repo
8:13:45 AM: ​
8:13:45 AM: ❯ Config file
8:13:45 AM:   /opt/build/repo/netlify.toml
8:13:45 AM: ​
8:13:45 AM: ❯ Context
8:13:45 AM:   deploy-preview
8:13:45 AM: ​
8:13:45 AM: ────────────────────────────────────────────────────────────────
8:13:45 AM:   1. build.command from netlify.toml                            
8:13:45 AM: ────────────────────────────────────────────────────────────────
8:13:45 AM: ​
8:13:45 AM: $ npm install && npm run build
8:13:46 AM: up to date, audited 605 packages in 856ms
8:13:46 AM: 71 packages are looking for funding
8:13:46 AM:   run `npm fund` for details
8:13:46 AM: 12 vulnerabilities (5 moderate, 6 high, 1 critical)
8:13:46 AM: To address issues that do not require attention, run:
8:13:46 AM:   npm audit fix
8:13:46 AM: To address all issues possible (including breaking changes), run:
8:13:46 AM:   npm audit fix --force
8:13:46 AM: Some issues need review, and may require choosing
8:13:46 AM: a different dependency.
8:13:46 AM: Run `npm audit` for details.
8:13:46 AM: > web@1.0.0 build
8:13:46 AM: > npm-run-all build:*
8:13:47 AM: > web@1.0.0 build:eleventy
8:13:47 AM: > cross-env ELEVENTY_ENV=prod NODE_OPTIONS=--max-old-space-size=4096 eleventy
8:13:47 AM: [11ty] Problem writing Eleventy templates: (more in DEBUG output)
8:13:47 AM: [11ty] > Cannot find module '../helpers/constants'
8:13:47 AM: Require stack:
8:13:47 AM: - /opt/build/repo/src/site/index.11tydata.js
8:13:47 AM: - /opt/build/repo/node_modules/@11ty/eleventy/src/TemplateData.js
8:13:47 AM: - /opt/build/repo/node_modules/@11ty/eleventy/src/Eleventy.js
8:13:47 AM: - /opt/build/repo/node_modules/@11ty/eleventy/cmd.js
8:13:47 AM: `Error` was thrown:
8:13:47 AM: [11ty]     Error: Cannot find module '../helpers/constants'
8:13:47 AM:     Require stack:
8:13:47 AM:     - /opt/build/repo/src/site/index.11tydata.js
8:13:47 AM:     - /opt/build/repo/node_modules/@11ty/eleventy/src/TemplateData.js
8:13:47 AM:     - /opt/build/repo/node_modules/@11ty/eleventy/src/Eleventy.js
8:13:48 AM: Creating deploy upload records
8:13:47 AM:     - /opt/build/repo/node_modules/@11ty/eleventy/cmd.js
8:13:47 AM:         at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
8:13:47 AM:         at Function.Module._load (node:internal/modules/cjs/loader:833:27)
8:13:47 AM:         at Module.require (node:internal/modules/cjs/loader:1057:19)
8:13:47 AM:         at require (node:internal/modules/cjs/helpers:103:18)
8:13:48 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
8:13:47 AM:         at Object.<anonymous> (/opt/build/repo/src/site/index.11tydata.js:3:18)
8:13:47 AM:         at Module._compile (node:internal/modules/cjs/loader:1155:14)
8:13:47 AM:         at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
8:13:47 AM:         at Module.load (node:internal/modules/cjs/loader:1033:32)
8:13:47 AM:         at Function.Module._load (node:internal/modules/cjs/loader:868:12)
8:13:47 AM:         at Module.require (node:internal/modules/cjs/loader:1057:19)
8:13:47 AM: [11ty] Benchmark    339ms  48%     1× (Data) `./src/site/_data/meta.js`
8:13:47 AM: [11ty] Wrote 0 files in 0.40 seconds (v1.0.0)
8:13:47 AM: ERROR: "build:eleventy" exited with 1.
8:13:47 AM: ​
8:13:47 AM: ────────────────────────────────────────────────────────────────
8:13:47 AM:   "build.command" failed                                        
8:13:47 AM: ────────────────────────────────────────────────────────────────
8:13:47 AM: ​
8:13:47 AM:   Error message
8:13:47 AM:   Command failed with exit code 1: npm install && npm run build (https://ntl.fyi/exit-code-1)
8:13:47 AM: ​
8:13:47 AM:   Error location
8:13:47 AM:   In build.command from netlify.toml:
8:13:47 AM:   npm install && npm run build
8:13:47 AM: ​
8:13:47 AM:   Resolved config
8:13:47 AM:   build:
8:13:47 AM:     command: npm install && npm run build
8:13:47 AM:     commandOrigin: config
8:13:47 AM:     environment:
8:13:47 AM:       - REVIEW_ID
8:13:47 AM:     publish: /opt/build/repo/dist
8:13:47 AM:     publishOrigin: config
8:13:47 AM:   redirects:
8:13:48 AM:     - from: /api/*
      status: 200
      to: /.netlify/functions/:splat
    - from: /*
      status: 404
      to: /404
  redirectsOrigin: config
Caching artifacts
8:13:48 AM: Started saving node modules
8:13:48 AM: Finished saving node modules
8:13:48 AM: Started saving build plugins
8:13:48 AM: Finished saving build plugins
8:13:48 AM: Started saving pip cache
8:13:48 AM: Finished saving pip cache
8:13:48 AM: Started saving emacs cask dependencies
8:13:48 AM: Finished saving emacs cask dependencies
8:13:48 AM: Started saving maven dependencies
8:13:48 AM: Finished saving maven dependencies
8:13:48 AM: Started saving boot dependencies
8:13:48 AM: Finished saving boot dependencies
8:13:48 AM: Started saving rust rustup cache
8:13:48 AM: Finished saving rust rustup cache
8:13:48 AM: Started saving go dependencies
8:13:48 AM: Finished saving go dependencies
8:13:48 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
8:13:48 AM: Failing build: Failed to build site
8:13:48 AM: Finished processing build request in 28.562902091s
oleeskild commented 1 year ago

This most likely has to do with the plugin version you are using. You will need the latest plugin version before updating the template. This is because there are sometimes added new files to the template, and you'll need the latest plugin so that it knows about these.

So try updating the plugin, then do another template update. Hopefully it should work properly then. Let me know how it goes 😄

oleeskild commented 1 year ago

Any luck @ksdavidc? Let me know if anything was unclear or if you need any help.

ksdavidc commented 1 year ago

thanks for checking. I have been a little busy this weekend and haven't had time to try it. I'll probably get to it next week, and will let you know how it goes. Thank you! :-)

On Sat, Dec 10, 2022 at 1:01 AM Ole Eskild Steensen < @.***> wrote:

Any luck @ksdavidc https://github.com/ksdavidc? Let me know if anything was unclear or if you need any help.

— Reply to this email directly, view it on GitHub https://github.com/oleeskild/obsidian-digital-garden/issues/119#issuecomment-1344479098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO2Y35DEQNTY5FNPX4Y7EZLWMNJUJANCNFSM6AAAAAASXN7KSE . You are receiving this because you were mentioned.Message ID: @.***>

ksdavidc commented 1 year ago

Alright, finally got to this. As you said, I updated the plugin and it seems to still be working. (Thanks) I attempted to update the template and the PR went through. There were some style changes to my headers, but I could put those in custom.css So far so good.

Except for one thing. I had made small modifications to the old repo. I needed to run a js file to format some of my code blocks, and I had to:

  1. add this to the page header: <script type="text/javascript" src="/js/scratchblocks.min.js"></script>
  2. add the referenced js file to [src/js/] (I might have had to create the folder as well, not sure. But it seems to have stayed...)
  3. put back a line that was removed was the line in .eleventy.js: eleventyConfig.addPassthroughCopy("src/site/js");
  4. add javascript to [src/site/_includes/layouts/note.njk] that uses the js file (added here for reference)
    <!-- provides scratchblock support 
    old selectors: div.blocks pre, .scratch, pre.language-scratchblock code, pre.language-scratchblock, .language-scratchblocks, div.callout-scratch pre, div.ad-scratch pre,
    new selectors: div.blocks pre, pre code.language-scratchblock, div.language-ad-scratch pre
    -->
    <script>
    scratchblocks.renderMatching('div.blocks pre, pre code.language-scratchblock, code.language-scratchblock, code.scratchblock, div.language-ad-scratch pre', {
    style:     'scratch3',   // Optional, defaults to 'scratch2'.
    scale: 1,                // Optional, defaults to 1
    });
    </script>

All but 2 I had to redo. You have made it easy to keep css changes with custom. I wonder if there is a better way to be able to preserve adding js, so I don't have to redo the changes every time there is a template update?

oleeskild commented 1 year ago

Great! Agreed. I've found myself being frustrated about the same thing. I will try to figure something out for making it easier to modify the garden, while still being able to update without it being overwiritten. I'll probably do something similar to the CSS solution, creating a folder where custom js can be added, that will automatically be added the page header. And will never be overwritten by a template update. Thanks for pointing that out.

ksdavidc commented 1 year ago

Oh, that's great to hear! All in all I am very satisfied with the plugin and it has really helped me put together a quick and easy webpage for teaching purposes without all the upkeep usually associated with setting up a webpage. For me this has worked better than the other solutions I tried. I am looking forward to playing with the new search and navbar...

ksdavidc commented 1 year ago

One thought just came to mind. I believe that in some cases it is better for the javascript to be loaded at the end (aka after page load), rather than the header... I don't know the rules for this, but I have run across that from time to time... e.g. https://stackoverflow.com/questions/1638670/javascript-at-bottom-top-of-web-page

oleeskild commented 1 year ago

Good catch! That was indeed true a few years ago. However, all modern browsers now supports the defer tag. This causes the script to be fetched asyncronously while the rest of the page continues to load and be parsed. This should be a bit faster than fetching them at the bottom of the page after all of the html had been downloaded and parsed.

ksdavidc commented 1 year ago

well whaddya know -- learn something new every day! Them googles sure is clever. 😸

oleeskild commented 1 year ago

@ksdavidc Recently @uroybd have done some tremendous work to make the template more "hackable". You can read about how it works in the docs. Closing this, as the basic customization need has been met. If you are missing something specific functionality, please let me know by opening a new PR 😄

ksdavidc commented 1 year ago

Thanks, that's great. I am definitely going to look into it! I really appreciate this plugin and appreciate your kind reply. :-)

ksdavidc commented 1 year ago

Got it to work. Hooray!

I did have one hiccup, and I don't know if it is my brain being porous, or something else:

I originally tried puttling a file.njk (user/common/...) with something like this:

<script type="text/javascript" src="scratchblocks.min.js"></script>

(tried header, footer, and after content)...with the js file in the same directory.

This line never seemed to appear in the output HTML. Maybe it couldn't find the JS? Syntax?

Eventually I took the original js file and wrapped in script

<script>
...
</script>

and that worked after content.

Slightly inconvenient as the js file is occasionally updated (no CDN as far as I know) and it would be nice to avoid having to restructure it each time.

What is supposed to happen?

uroybd commented 1 year ago

The 1st example should work with correct path.

uroybd commented 1 year ago

However, we don't have a passThroughCopy settings for additional js. I'll open a PR for that.

ksdavidc commented 1 year ago

The 1st example should work with correct path.

In my case, I had the js file in the same directory as the njk file. I assumed it would look in this directory first. Should I have put the path more explicitly? Maybe it was looking in the src root first?

uroybd commented 1 year ago

The 1st example should work with correct path.

In my case, I had the js file in the same directory as the njk file. I assumed it would look in this directory first. Should I have put the path more explicitly? Maybe it was looking in the src root first?

Once this PR gets merged, you will be able to put the script in src/site/scripts and refer it as /script/your-script-filename.js.

Putting that to the njk file's directory won't work. Since only njk files are being processed from those places.

ksdavidc commented 1 year ago

The 1st example should work with correct path.

In my case, I had the js file in the same directory as the njk file. I assumed it would look in this directory first. Should I have put the path more explicitly? Maybe it was looking in the src root first?

Once this PR gets merged, you will be able to put the script in src/site/scripts and refer it as /script/your-script-filename.js.

Putting that to the njk file's directory won't work. Since only njk files are being processed from those places.

I see. Sorry if it was a niggly question. I am not really on top of this kind of stuff, and was just guessing my way through. Your answer was very clear, so thank you.

uroybd commented 1 year ago

The 1st example should work with correct path.

In my case, I had the js file in the same directory as the njk file. I assumed it would look in this directory first. Should I have put the path more explicitly? Maybe it was looking in the src root first?

Once this PR gets merged, you will be able to put the script in src/site/scripts and refer it as /script/your-script-filename.js. Putting that to the njk file's directory won't work. Since only njk files are being processed from those places.

I see. Sorry if it was a niggly question. I am not really on top of this kind of stuff, and was just guessing my way through. Your answer was very clear, so thank you.

No problem at all. These questions allow us to identify UX problems.