Build pathnames taking into account the thread slug.

This commit is contained in:
Mayhem 2014-04-30 15:30:46 +02:00
parent 2de487906c
commit a9b05047be
7 changed files with 19 additions and 13 deletions

View File

@ -1,4 +1,4 @@
<a href="/#{thread.board}/thread/#{thread.ID}" class="thumb"></a> <a href="#{Build.path thread.board.ID, thread.ID}" class="thumb"></a>
<div class="thread-stats" title="Post count / File count / Page count"> <div class="thread-stats" title="Post count / File count / Page count">
<span class="post-count">#{postCount}</span> / <span class="file-count">#{fileCount}</span> / <span class="page-count">#{pageCount}</span> <span class="post-count">#{postCount}</span> / <span class="file-count">#{fileCount}</span> / <span class="page-count">#{pageCount}</span>
<span class="thread-icons"></span> <span class="thread-icons"></span>

View File

@ -15,6 +15,11 @@ Build =
thumbRotate: do -> thumbRotate: do ->
n = 0 n = 0
-> n = (n + 1) % 2 -> n = (n + 1) % 2
path: (boardID, threadID, postID, fragment) ->
path = "/#{boardID}/thread/#{threadID}"
path += "/#{g.SLUG}" if g.SLUG? and threadID is g.THREADID
path += "##{fragment or 'p'}#{postID}" if postID
path
postFromObject: (data, boardID) -> postFromObject: (data, boardID) ->
o = o =
# id # id
@ -175,7 +180,7 @@ Build =
if isOP and g.VIEW is 'index' if isOP and g.VIEW is 'index'
pageNum = Index.liveThreadIDs.indexOf(postID) // Index.threadsNumPerPage + 1 pageNum = Index.liveThreadIDs.indexOf(postID) // Index.threadsNumPerPage + 1
pageIcon = " <span class=page-num title='This thread is on page #{pageNum} in the original index.'>Page #{pageNum}</span>" pageIcon = " <span class=page-num title='This thread is on page #{pageNum} in the original index.'>Page #{pageNum}</span>"
replyLink = " &nbsp; <span>[<a href='/#{boardID}/thread/#{threadID}' class=replylink>Reply</a>]</span>" replyLink = " &nbsp; <span>[<a href='#{Build.path boardID, threadID}' class=replylink>Reply</a>]</span>"
else else
pageIcon = replyLink = '' pageIcon = replyLink = ''
@ -203,12 +208,12 @@ Build =
' </span> ' + ' </span> ' +
"<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " + "<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " +
"<span class='postNum'>" + "<span class='postNum'>" +
"<a href=#{"/#{boardID}/thread/#{threadID}#p#{postID}"} title='Highlight this post'>No.</a>" + "<a href=#{Build.path boardID, threadID, postID} title='Highlight this post'>No.</a>" +
"<a href='#{ "<a href='#{
if g.VIEW is 'thread' and g.THREADID is threadID if g.VIEW is 'thread' and g.THREADID is threadID
"javascript:quote(#{postID})" "javascript:quote(#{postID})"
else else
"/#{boardID}/thread/#{threadID}#q#{postID}" Build.path boardID, threadID, postID, 'q'
}' title='Quote this post'>#{postID}</a>" + }' title='Quote this post'>#{postID}</a>" +
pageIcon + sticky + closed + replyLink + pageIcon + sticky + closed + replyLink +
'</span>' + '</span>' +
@ -220,11 +225,11 @@ Build =
'</div>' '</div>'
# Fix quote pathnames in index or cross-{board,thread} posts
for quote in $$ '.quotelink', container for quote in $$ '.quotelink', container
href = quote.getAttribute 'href' href = quote.getAttribute 'href'
continue if href[0] is '/' # Cross-board quote, or board link continue unless href[0] is '#'
href = "#{threadID}#{href}" if href[0] is '#' quote.href = Build.path boardID, threadID, href[2..]
quote.href = "/#{boardID}/thread/#{href}" # Fix pathnames
container container
@ -236,7 +241,7 @@ Build =
$.el 'a', $.el 'a',
className: 'summary' className: 'summary'
textContent: text.join ' ' textContent: text.join ' '
href: "/#{boardID}/thread/#{threadID}" href: Build.path boardID, threadID
thread: (board, data) -> thread: (board, data) ->
Build.spoilerRange[board] = data.custom_spoiler Build.spoilerRange[board] = data.custom_spoiler

View File

@ -14,6 +14,7 @@ Main =
return return
if g.VIEW is 'thread' if g.VIEW is 'thread'
g.THREADID = +pathname[3] g.THREADID = +pathname[3]
g.SLUG = pathname[4] if pathname[4]?
# flatten Config into Conf # flatten Config into Conf
# and get saved or default values # and get saved or default values

View File

@ -187,7 +187,7 @@ Keybinds =
open: (thread, tab) -> open: (thread, tab) ->
return if g.VIEW isnt 'index' return if g.VIEW isnt 'index'
url = "/#{thread.board}/thread/#{thread}" url = Build.path thread.board.ID, thread.ID
if tab if tab
$.open url $.open url
else else

View File

@ -587,9 +587,9 @@ QR =
QR.cooldown.set {req, post, isReply, threadID} QR.cooldown.set {req, post, isReply, threadID}
URL = if threadID is postID # new thread URL = if threadID is postID # new thread
"/#{g.BOARD}/thread/#{threadID}" Build.path g.BOARD.ID, threadID
else if g.VIEW is 'index' and !QR.cooldown.auto and Conf['Open Post in New Tab'] # replying from the index else if g.VIEW is 'index' and !QR.cooldown.auto and Conf['Open Post in New Tab'] # replying from the index
"/#{g.BOARD}/thread/#{threadID}#p#{postID}" Build.path g.BOARD.ID, threadID, postID
if URL if URL
if Conf['Open Post in New Tab'] if Conf['Open Post in New Tab']
$.open URL $.open URL

View File

@ -49,7 +49,7 @@ QuoteBacklink =
buildBacklink: (quoted, quoter) -> buildBacklink: (quoted, quoter) ->
frag = QuoteBacklink.frag.cloneNode true frag = QuoteBacklink.frag.cloneNode true
a = frag.lastElementChild a = frag.lastElementChild
a.href = "/#{quoter.board}/thread/#{quoter.thread}#p#{quoter}" a.href = Build.path quoter.board.ID, quoter.thread.ID, quoter.ID
a.textContent = text = QuoteBacklink.funk quoter.ID a.textContent = text = QuoteBacklink.funk quoter.ID
if quoter.isDead if quoter.isDead
$.addClass a, 'deadlink' $.addClass a, 'deadlink'

View File

@ -40,7 +40,7 @@ Quotify =
# Don't add 'deadlink' when quotifying in an archived post, # Don't add 'deadlink' when quotifying in an archived post,
# and we don't know if the post died yet. # and we don't know if the post died yet.
a = $.el 'a', a = $.el 'a',
href: "/#{boardID}/thread/#{post.thread}#p#{postID}" href: Build.path boardID, post.thread.ID, postID
className: if post.isDead then 'quotelink deadlink' else 'quotelink' className: if post.isDead then 'quotelink deadlink' else 'quotelink'
textContent: quote textContent: quote
$.extend a.dataset, {boardID, threadID: post.thread.ID, postID} $.extend a.dataset, {boardID, threadID: post.thread.ID, postID}