diff --git a/.gitignore b/.gitignore index 770a198..f7b2021 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ _site .claude/ .idea/ .run/ -_posts_bak/ # Editor and toolchain leftovers node_modules/ diff --git a/_config.yml b/_config.yml index a183c0f..a94e599 100644 --- a/_config.yml +++ b/_config.yml @@ -156,11 +156,7 @@ social: protocols: - # Default social card image, used only when a page sets no `cover`. The old - # value was my_logo.png declared as 612x605 — the file is actually 192x192, - # below the 200x200 floor Facebook/LinkedIn need to render a card at all. - # my_header_image.jpg is the site cover and its declared size is real. + # Default social card image, used only when a page sets no `cover` (the site + # cover; at least 200x200, or Facebook/LinkedIn render no card). head.html + # reads its size from the file. fb_image: /assets/my_header_image.jpg - fb_image_width: 1920 - fb_image_height: 600 - fb_image_type: image/jpeg diff --git a/_includes/head.html b/_includes/head.html index da0854d..4174d24 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -10,15 +10,13 @@ {%- assign page_description = page.description | default: site.description | shorten_meta -%} {%- comment -%} - A page `cover` is a wide banner of unknown size, so its dimensions are not - declared — crawlers measure it themselves. Only the configured default image - ships width/height, because those values are verified against the file. + The page's cover, else the site's default image. Its size is read from the + file (image_size, _plugins/image_dimensions.rb), so a link preview can lay + out before the image arrives. {%- endcomment -%} -{%- if page.cover -%} - {%- assign social_image = page.cover | prepend: site.baseurl | prepend: site.url -%} -{%- else -%} - {%- assign social_image = site.protocols.fb_image | prepend: site.baseurl | prepend: site.url -%} -{%- endif -%} +{%- assign social_src = page.cover | default: site.protocols.fb_image -%} +{%- assign social_image = social_src | prepend: site.baseurl | prepend: site.url -%} +{%- assign social_size = social_src | image_size -%} {%- assign page_lang = page.lang | default: site.lang -%} {%- if page_lang == 'en' -%} @@ -122,10 +120,10 @@ - {% unless page.cover %} - - - {% endunless %} + + {% if social_size %} + + {% endif %} {% if page.layout == 'post' %} {% if page.last_modified_at %} @@ -185,6 +183,10 @@ "image": "{{ social_image }}", "author": { "@type": "Person", "name": {{ site.author | jsonify }}, "url": "{{ '/about/' | prepend: site.baseurl | prepend: site.url }}" }, "publisher": { "@type": "Person", "name": {{ site.author | jsonify }} }, + {%- comment -%} The paper a paper post is about, by its DOI. {%- endcomment -%} + {%- if page.paper_doi %} + "about": { "@type": "ScholarlyArticle", "name": {{ page.title | jsonify | replace: '<', '\u003c' }}, "identifier": {{ page.paper_doi | jsonify }}, "sameAs": {{ page.paper_doi | prepend: 'https://doi.org/' | jsonify }} }, + {%- endif %} "keywords": {{ page.tags | join: ', ' | replace: '-', ' ' | jsonify | replace: '<', '\u003c' }} } @@ -219,12 +221,12 @@ diff --git a/test/test_fetch_citations.rb b/test/test_fetch_citations.rb index a8145fe..0dd5794 100644 --- a/test/test_fetch_citations.rb +++ b/test/test_fetch_citations.rb @@ -129,9 +129,10 @@ def test_published_counts_are_taken_only_in_the_shape_written LIVE = "https://example.org/citations.json" # run() in a scratch dir; returns [what it returned, the file, the notes]. - def run_with(*answers, key: "") + def run_with(*answers, key: "", existing: nil) Dir.mktmpdir do |dir| out = File.join(dir, "citations.json") + File.write(out, existing) if existing notes = [] answering(*answers) data = CitationFetch.run(%w[arXiv:1 arXiv:2], out: out, published_url: LIVE, key: key, @@ -176,9 +177,10 @@ def test_an_unusable_answer_falls_back_too end def test_with_nothing_to_write_the_file_is_left_alone - data, file, notes = run_with(*Array.new(5) { response(429) }, response(404)) + before = JSON.generate("fetched_at" => "2026-11-01T00:00:00Z", "papers" => {}) + data, file, notes = run_with(*Array.new(5) { response(429) }, response(404), existing: before) assert_nil data - assert_nil file + assert_equal JSON.parse(before), file assert_match(/not updated/, notes.last[1]) end end diff --git a/test/test_image_dimensions.rb b/test/test_image_dimensions.rb index 887b751..fbe4839 100644 --- a/test/test_image_dimensions.rb +++ b/test/test_image_dimensions.rb @@ -6,6 +6,8 @@ # themselves rather than to whichever files happen to be in assets/. require "minitest/autorun" +require "tmpdir" +require "fileutils" require_relative "../_plugins/image_dimensions" class TestImageDimensions < Minitest::Test @@ -85,4 +87,17 @@ def test_leaves_the_tag_alone_when_the_file_is_missing_or_unreadable assert_equal html, ImageDimensions.apply(html) { nil } assert_equal html, ImageDimensions.apply(html) { "not an image" } end + + # The filter head.html declares the social image's size with. + def test_image_size_reads_a_repo_file_and_nil_for_none + Dir.mktmpdir do |dir| + FileUtils.mkdir_p(File.join(dir, "assets")) + File.binwrite(File.join(dir, "assets/c.jpg"), jpeg(1920, 1005)) + filter = Object.new.extend(ImageSizeFilter) + site = Struct.new(:source).new(dir) + filter.instance_variable_set(:@context, Struct.new(:registers).new({ site: site })) + assert_equal [1920, 1005], filter.image_size("/assets/c.jpg") + assert_nil filter.image_size("/assets/missing.jpg") + end + end end diff --git a/test/test_post_toc.rb b/test/test_post_toc.rb index 9925701..fb84733 100644 --- a/test/test_post_toc.rb +++ b/test/test_post_toc.rb @@ -11,8 +11,28 @@ def toc(html) end def test_one_entry_per_h2_with_an_id - html = %(
x
x