Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 09 18:08
    ddfreyne labeled #1543
  • Apr 05 09:55

    ddfreyne on 4.12.1

    Always write stack trace backwa… Merge branch 'stack-trace-alway… Expand paths in a more backward… and 5 more (compare)

  • Apr 05 09:55

    ddfreyne on 4.12.0

    (compare)

  • Apr 05 09:54

    ddfreyne on main

    Always write stack trace backwa… Merge branch 'stack-trace-alway… Expand paths in a more backward… and 5 more (compare)

  • Apr 05 09:53

    ddfreyne on 4.12.1

    (compare)

  • Apr 05 09:15
    ddfreyne commented #1543
  • Apr 05 09:14
    ddfreyne commented #1543
  • Apr 05 09:04

    ddfreyne on bundler

    (compare)

  • Apr 05 09:03

    ddfreyne on main

    Bump kramdown from 2.3.0 to 2.3… Merge pull request #254 from na… (compare)

  • Apr 05 09:03
    ddfreyne closed #254
  • Apr 04 08:53

    ddfreyne on main

    Upgrade Rubocop (compare)

  • Mar 29 16:38
    dependabot[bot] labeled #254
  • Mar 29 16:38
    dependabot[bot] opened #254
  • Mar 29 16:38

    dependabot[bot] on bundler

    Bump kramdown from 2.3.0 to 2.3… (compare)

  • Mar 24 19:21
    Ecco edited #1543
  • Mar 24 19:20
    Ecco opened #1543
  • Mar 22 10:09
    iay commented #1541
  • Mar 17 20:30

    ddfreyne on main

    Expand paths in filesystem data… Merge branch 'expand-dirs-in-fi… Add universal license at root (compare)

  • Mar 09 20:39
    tammersaleh edited #1542
  • Mar 09 20:38
    tammersaleh closed #1542
Christian Tietze
@DivineDominion
Christian Tietze
@DivineDominion
sweet, it does the trick and doesn't even take that long!
  def find_backlinks
    backlinks_to = {}
    skipped_notes = ["/posts/overview"]
    domain = config[:base_url]
    # Start with the domain, or be inside a (/...) Markdown inline link or a [...]: reference style link
    link_regex = /(?<=#{domain}\/|\(\/|\: \/)(.*?)(?:="|\)|\s|$)/

    def remove_trailing_slash(str)
      if str[-1..] == "/"
        str[...-1]
      else
        str
      end
    end

    @items.find_all('/posts/**/*').each do |origin|
      next if origin.binary?
      next if skipped_notes.include?(origin.identifier.without_exts)
      # transform links into a format that looks like `identifier.without_ext`
      linked_paths = origin.raw_content
                       .scan(link_regex)
                       .map { |m| "/" + remove_trailing_slash(m[0]) }
      linked_paths.each do |linked_path|
        backlinks_to[linked_path] ||= []
        backlinks_to[linked_path] << origin.identifier
      end
    end

    @items.find_all('/posts/**/*').each do |target|
      next if target.binary?
      next if skipped_notes.include?(target.identifier.without_exts)
      target[:backlinks] = backlinks_to.fetch(target.identifier.without_exts, [])
    end
  end

  find_backlinks # before adding the tag index etc.
now I have to cheat because I store links by path, but look up by ID 🙄
Christian Tietze
@DivineDominion
needed to clean up /index.* from the paths, too, for canonical lookup
Denis Defreyne
@ddfreyne
Yeah, I like using the identifier whereever I can, and then look up the path when it’s necessary
It works better for me, because I need the items so I can sort by title later on
Christian Tietze
@DivineDominion
nanoc compile -W is nice, but surprisingly "hidden": I kinda expected nanoc watch to work and be listed among the commands in nanoc help
Good news (for me at least) is that nanoc-live auto-compiles my sites without mysteriously affecting my Emacs modeline colors. Never figured out why running guard would do that.
Very happy with that, good work @ddfreyne :)
Christian Tietze
@DivineDominion
odd observation: def foo;end in lib/default.rb makes foo() available in a preprocess do block, but adding the same right before the preprocess line won't
weird because it's in the same file and I thought the scope would by default work
Denis Defreyne
@ddfreyne

nanoc compile -W is nice, but surprisingly "hidden"

Yes, indeed… though it’s more of a consistency thing: nanoc live is the command to use, and it essentially wraps nanoc view and nanoc compile --watch.

odd observation: def foo;end in lib/default.rb makes foo() available in a preprocess do block, but adding the same right before the preprocess line won't

This has to do with Ruby’s scoping setup. The Rules file is evalulated in one scope, but the individual rules themselves are evaluated in a different one. (And the files in lib/ live in another scope—the global one.)

I also think it’s confusing, but haven’t found an alternative way that works (and remains backwards compatible)!

ckoshikumo
@ckoshikumo

Hey everyone. I thought I'd come back and post my solution to the problem I asked help with. This preprocess block will use :mtime and a separate (and auto generated) meta file to keep track of the updates and, hopefully, make item[:updated_at] automatically available only when relevant. Maybe there's a simpler way to achieve this but this is the best I got for now!

Thanks for the help!

preprocess do
  def prepare_blog_articles
    now = Time.now.round

    @items.select { |i| i.identifier.to_s =~ %r{^/blog/[^_]} }.each do |item|
      if item[:meta_filename]
        item_check_updates(item, now)
      else
        item_first_publish(item, now)
      end
    end
  end

  def item_first_publish(item, now)
    item[:created_at] = now
    item[:last_updated_at] = now

    create_meta_file(item, now)
    update_mtime(item, now)
  end

  def item_check_updates(item, now)
    # Abnormal cases; if this happens, it was a mistake and must be fixed manually:
    abort "#{item[:meta_filename]} should contain 'created_at' info" unless item.key?(:created_at)
    abort "#{item[:meta_filename]} should contain 'last_updated_at' info" unless item.key?(:last_updated_at)

    # We only set item[:updated_at] if we want that info to appear in the final
    # rendering of the item. If the item has never been updated, both fields in
    # the meta file should be equal here. Otherwise we use the :last_updated_at
    # as the most recent date.
    if item[:last_updated_at] != item[:created_at]
      item[:updated_at] = item[:last_updated_at]
    end

    # But maybe the item has been updated but the meta file hasn't. In that
    # case, item[:mtime] will not be equal to item[:last_updated_at]. So we set
    # the revelant values for NOW and record them. (This may override
    # item[:update_at] if it was set in the previously if block, but that is by
    # design: it means the item was updated again after the last update.)
    if item[:last_updated_at].to_i != item[:mtime].to_i
      item[:updated_at] = now

      update_meta_file(item, now)
      update_mtime(item, now)
    end
  end

  def create_meta_file(item, now)
    meta_filename = Pathname(item.raw_filename).sub_ext(".yaml")
    File.open(meta_filename, 'wb') { |f| f.write "created_at: #{now}\nlast_updated_at: #{now}\n" }
  end

  def update_meta_file(item, now)
    meta_content = IO.read(item[:meta_filename])
    IO.write(item[:meta_filename], meta_content.sub(/^last_updated_at:.+/, "last_updated_at: #{now}"))
  end

  def update_mtime(item, now)
    File.utime(now, now, item.raw_filename)
  end

  prepare_blog_articles
end
Christian Tietze
@DivineDominion
sweet! Good to hear it works
Christian Tietze
@DivineDominion
:point_up: March 9, 2021 10:00 PM @ddfreyne sounds like nanoc live should work, but it doesn't-- "nanoc: unknown command 'live'"
Denis Defreyne
@ddfreyne
@DivineDominion Can you verify that you have the nanoc-live gem added to your Gemfile?
It’s a separate thing (not bundled with Nanoc)
Christian Tietze
@DivineDominion
via bundler, yes, and the -W flag works
Denis Defreyne
@ddfreyne
You’ll explicitly have to add it into the nanoc group inside the Gemfile — otherwise Nanoc won’t auto-load it
Christian Tietze
@DivineDominion
I see. I don't use groups :)
Christian Tietze
@DivineDominion
tried it, works now. Cool!
Gregory Pakosz
@gpakosz
Hi there

Long time I didn't compile a nanoc site of mine and I'm hitting

Current item: /api.md (:default representation)

  0. _factory/lib/items.rb:47:in `path'
  1. /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html/document.rb:171:in `parse'
  2. /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html/document_fragment.rb:42:in `initialize'
  3. /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html/document_fragment.rb:23:in `new'
  4. /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html/document_fragment.rb:23:in `parse'
  5. /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html.rb:31:in `fragment'
  6. _factory/lib/filters/rouge.rb:9:in `run'

Somewhat nokogiri tries to call a path function which is bound to my own code in lib/ 😐

I'm not sure how I can solve that 🤔
Here is /usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/html/document.rb:171
          url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
Gregory Pakosz
@gpakosz
And here's my items.rb helper content
    def path(target, params = {})
      ...
Gregory Pakosz
@gpakosz
I changed nothing beside upgrading gems 😞
Gregory Pakosz
@gpakosz
Oops forgot to cite the error
ArgumentError: wrong number of arguments (given 0, expected 1..2)
And maybe Ruby 3 is part of the problem
Denis Defreyne
@ddfreyne
@gpakosz Can you share the full items.rb helper (maybe as a gist)?
And the crash.log in full as well, if you have that
Gregory Pakosz
@gpakosz
Because it's also used on a work project I can share items.rb in private.
In the meantime I'll try to get a repro on a simple site
Denis Defreyne
@ddfreyne
I’m guessing it will compile fine on Ruby 2.7; I know that Ruby 3.0 changed some behavior
Denis Defreyne
@ddfreyne
Quick follow-up here: replacing include MyHelper with use_helper MyHelper did the trick!
Gregory Pakosz
@gpakosz
Indeed it compiles fine on Ruby 2.7

So yeah for the readers. My items.rb files was defined the following way

module NanocFactory
  module Items
    def path(target, params = {})
      ...
    end
end
include NanocFactory::Items

And I never realized it would add a #path() instance method on all objects!

The solution is indeed to replace include NanocFactory::Items with use_helper NanocFactory::Items
Now I'm of course curious what changed and why it somewhat worked before
Denis Defreyne
@ddfreyne
I’m also curious why it works on Ruby 2.7… I don’t understand :)
Christian Tietze
@DivineDominion
@gpakosz maybe copypasta mangled up, but there's an end missing in your code; could the include directive be applied to NanocFactory?
Gregory Pakosz
@gpakosz
indeed it's a typo
too late to edit
Christian Tietze
@DivineDominion
at least then it's irrelevant :)
Beni Bilme
@benibilme_gitlab
I am completely newbie to nanoc. I am reading the documentation. I stumbled across to nanoc while searching for a static site generator to be used with asciidoctor. I have seen that asciidoctor filter is defined but I could not understant how to pass command line parameters to asciidoctor command via filter.
Any help much appreciated.
Denis Defreyne
@ddfreyne
@benibilme_gitlab Hey there! I’ve replied to you on the mailing list: https://groups.google.com/g/nanoc/c/hUUPVMUpehw/m/4exVFqwZDAAJ
Christian Tietze
@DivineDominion
I want to experiment with wiki links on top of Markdown rendering. I started with an extension to Rouge last year that limits the regex to inline styles, but never got anywhere with that. I wonder if a filter after the Rouge filter would work, too, searching for all [[....]] occurrences. But I still want to limit these to non-code/non-pre tags.
What would y'all think is the most performant way to get there? Using Nokogiri to parse the HTML result thus far sounds a bit like overkill. Maybe from the character offset of the match, scan backwards to find the enclosing tag?
Denis Defreyne
@ddfreyne
@DivineDominion I wonder if you could create your own Kramdown parser for it — it seems feasible: https://github.com/gettalong/kramdown/blob/master/lib/kramdown/parser/kramdown.rb