mirror of
https://git.sr.ht/~edwardloveall/scribe
synced 2025-12-10 12:41:23 +00:00
Add unique ID to headings
The `name` field on the `paragraph` type contains a unique ID for the paragraph. It's not guaranteed to be there, on images for example like in the `fd8d091ab8ef` post, but it's there for everything else I can find. This enables deep linking. There's no way to get to the deep link other than opening up the web console. I wanted to link every heading, but you can actually have links in part of a heading so that's not tenable. Maybe a "permalink" link next to every heading?
This commit is contained in:
@@ -16,15 +16,15 @@ class ParagraphConverter
|
||||
when PostResponse::ParagraphType::H2
|
||||
paragraph = paragraphs.shift
|
||||
children = MarkupConverter.convert(paragraph.text, paragraph.markups)
|
||||
node = Heading1.new(children: children)
|
||||
node = Heading1.new(children: children, identifier: paragraph.name || "")
|
||||
when PostResponse::ParagraphType::H3
|
||||
paragraph = paragraphs.shift
|
||||
children = MarkupConverter.convert(paragraph.text, paragraph.markups)
|
||||
node = Heading2.new(children: children)
|
||||
node = Heading2.new(children: children, identifier: paragraph.name || "")
|
||||
when PostResponse::ParagraphType::H4
|
||||
paragraph = paragraphs.shift
|
||||
children = MarkupConverter.convert(paragraph.text, paragraph.markups)
|
||||
node = Heading3.new(children: children)
|
||||
node = Heading3.new(children: children, identifier: paragraph.name || "")
|
||||
when PostResponse::ParagraphType::IFRAME
|
||||
paragraph = paragraphs.shift
|
||||
node = EmbeddedConverter.convert(paragraph, gist_store)
|
||||
|
||||
@@ -27,6 +27,7 @@ class MediumClient
|
||||
content {
|
||||
bodyModel {
|
||||
paragraphs {
|
||||
name
|
||||
text
|
||||
type
|
||||
href
|
||||
|
||||
@@ -93,15 +93,15 @@ class PageContent < BaseComponent
|
||||
end
|
||||
|
||||
def render_child(node : Heading1)
|
||||
h1 { render_children(node.children) }
|
||||
h1(id: node.identifier) { render_children(node.children) }
|
||||
end
|
||||
|
||||
def render_child(node : Heading2)
|
||||
h2 { render_children(node.children) }
|
||||
h2(id: node.identifier) { render_children(node.children) }
|
||||
end
|
||||
|
||||
def render_child(node : Heading3)
|
||||
h3 { render_children(node.children) }
|
||||
h3(id: node.identifier) { render_children(node.children) }
|
||||
end
|
||||
|
||||
def render_child(child : Image)
|
||||
|
||||
@@ -41,12 +41,24 @@ module Nodes
|
||||
end
|
||||
|
||||
class Heading1 < Container
|
||||
getter identifier : String
|
||||
|
||||
def initialize(@children : Children, @identifier : String)
|
||||
end
|
||||
end
|
||||
|
||||
class Heading2 < Container
|
||||
getter identifier : String
|
||||
|
||||
def initialize(@children : Children, @identifier : String)
|
||||
end
|
||||
end
|
||||
|
||||
class Heading3 < Container
|
||||
getter identifier : String
|
||||
|
||||
def initialize(@children : Children, @identifier : String)
|
||||
end
|
||||
end
|
||||
|
||||
class ListItem < Container
|
||||
|
||||
@@ -32,6 +32,7 @@ class PostResponse
|
||||
end
|
||||
|
||||
class Paragraph < Base
|
||||
property name : String?
|
||||
property text : String?
|
||||
property type : ParagraphType
|
||||
property markups : Array(Markup)
|
||||
@@ -40,6 +41,7 @@ class PostResponse
|
||||
property metadata : Metadata?
|
||||
|
||||
def initialize(
|
||||
@name : String,
|
||||
@text : String?,
|
||||
@type : ParagraphType,
|
||||
@markups : Array(Markup),
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Scribe
|
||||
VERSION = "2022-11-06"
|
||||
VERSION = "2023-03-25"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user