Showing 415 to 418 Newer

Svelte: Redirect to new page ID

Suppose

  • that your website has page IDs in the sense of domain.com/PAGEID/slug. For example, you're probably seeing this very page at the address edstrom.dev/csbxq/redirect-to-new-page-ids-in-sveltekit, so the ID is csbxq.
  • that you update the ID to use new algorithm, so now it's going to be 6uXpfOI2c9fJdh2aa22. Time to set up a redirect!

I'll assume your page's loader (the file you've got on a path like src/routes/[id]/[[slug]]/+page.js) contains this:

import { error } from '$sveltejs/kit'
import posts from '$lib/posts.json'

export function load({ params }) {
    let post = posts[params.id]
    if (post) return post
    
    error(404, "Not found")
}

Edit that to something like this.

import { error, redirect } from '$sveltejs/kit'
import posts from '$lib/posts.json'
import v1_to_v2 from '$lib/v1_to_v2.json' // assumed a table of old and new ID

export function load({ params }) {
  let post = posts[params.id]
  if (post) return post

  // Redirect from v1 to v2 id
  let idv2 = v1_to_v2[params.id]
  if (idv2) redirect(308, `/${idv2}`)
  
  error(404, "Not found")
}

This assumes that navigating to just domain.com/IDV2 is satisfactory.

To also include the slug in the redirection (remember the slug in domain.com/PAGEID/slug?), I'll assume your post object contains metadata post.id and post.slug and then we can do the redirection like this:

// ...
export function load({ params }) {
  let post = posts[params.id]
  if (post) return post

  // Redirect from v1 to v2 id
  post = posts[v1_to_v2[params.id]]
  if (post) redirect(308, `/${post.id}/${post.slug}`)

  error(404, "Not found")
}
Created (2 weeks ago)

Nested notes enable folgezettel (note-sequences)

#org-roam

The packages zk, orgrr and denote mandate the rule of "one note per file". So how do they do note-sequences?

Well. In orgrr, you'd manually give special IDs to notes that should be parts of sequences, and then use commands like orgrr-show-sequence to work with them.

In org-roam, which permits nested notes, you'd just have a series of headings in a single file… you know, a conventional org-mode file.

I like that better. You can export it to PDF or HTML. There are ways to isolate and export a subtree from one file, but it's not as convenient (yet) to tell Org to concatenate multiple whole files and export them as one.

I suppose zk/orgrr/denote users could use org-transclusion to get the same effect.

Multiple sequences?

Hm… the concept of orgrr-show-sequence has merit. Nesting org-roam nodes only gives you one sequence. What if you want a node to be part of several?

For example, say you have a node about Isaac Newton, which could be part of both a Philosophy sequence and a Math sequence.

Well, you could have a "Math" note that transcludes all other math notes, and a "Philosophy" note that transcludes all the philosophy notes. And that works whether you use orgrr or org-roam. But yea, org-roam's ability to nest nodes suddenly became less important.

Created (3 weeks ago)

Semantic tabs in 2024

There is a little-used #emacs package for smart tabs:

(require 'smart-tabs-mode)
(smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby 'nxml)
(add-hook 'c-mode-common-hook #'indent-tabs-mode)
(add-hook 'java-mode-hook #'indent-tabs-mode)
(add-hook 'js2-mode-hook #'indent-tabs-mode)
(add-hook 'cperl-mode-hook #'indent-tabs-mode)
(add-hook 'python-mode-hook #'indent-tabs-mode)
(add-hook 'ruby-mode-hook #'indent-tabs-mode)
(add-hook 'nxml-mode-hook #'indent-tabs-mode)

I like the idea, but as far as I can tell, such a package is stillborn.

Autoformatters like gofmt do smart tabs for you these days, and langs without autoformatters are always gonna have people messing up the indentation. So until there is an .editorconfig rule for smart tabs, stick with either spaces only, or an autoformatter.

Discussion github.com/editorconfig/editorconfig/issues/323

(Once that's finalized, then Emacs is gonna need a new way more general smart-tabs-mode! Probably based on tree-sitter.)

Someone points out the indent_style = tabs rule actually makes no sense if it's not smart tabs anyway, so it might be assumed by the tabs rule. Makes you think who was using the tabs rule before…

I.e. the choices are:

  • Spaces only: OK
  • Smart tabs: OK
  • Tabs only: never
Created (4 weeks ago)

Watch the timer-list work in realtime

#emacs

You know the list-timers command? It shows you all the active timers, but it's a snapshot frozen in time, at the moment you ran the command.

I was curious to watch the timers count down, so I made this command.

(let ((this-timer (timer-create)))
  (defun my-timer-list-animate ()
    "Start auto-refreshing the \\[list-timers] buffer.
Stop once the buffer is no longer visible."
    (interactive)
    (cancel-timer this-timer)
    (let ((buf (get-buffer "*timer-list*")))
      (when (and buf (get-buffer-window buf 'visible))
        (run-with-timer .2 nil #'my-timer-list-animate)
        (save-window-excursion
          (save-excursion
            (with-current-buffer buf
              (revert-buffer))))))))
(keymap-set timer-list-mode-map "a" #'my-timer-list-animate)

Interestingly, the idle timers still aren't shown to count down, even though idle-time is going up! I'm guessing list-timers never was meant for that, so it takes a shortcut by just showing the max time regardless.

Created (4 weeks ago)
Showing 415 to 418 Newer