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">
<span class="post-count">#{postCount}</span> / <span class="file-count">#{fileCount}</span> / <span class="page-count">#{pageCount}</span>
<span class="thread-icons"></span>

View File

@ -15,6 +15,11 @@ Build =
thumbRotate: do ->
n = 0
-> 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) ->
o =
# id
@ -175,7 +180,7 @@ Build =
if isOP and g.VIEW is 'index'
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>"
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
pageIcon = replyLink = ''
@ -203,12 +208,12 @@ Build =
' </span> ' +
"<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " +
"<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='#{
if g.VIEW is 'thread' and g.THREADID is threadID
"javascript:quote(#{postID})"
else
"/#{boardID}/thread/#{threadID}#q#{postID}"
Build.path boardID, threadID, postID, 'q'
}' title='Quote this post'>#{postID}</a>" +
pageIcon + sticky + closed + replyLink +
'</span>' +
@ -220,11 +225,11 @@ Build =
'</div>'
# Fix quote pathnames in index or cross-{board,thread} posts
for quote in $$ '.quotelink', container
href = quote.getAttribute 'href'
continue if href[0] is '/' # Cross-board quote, or board link
href = "#{threadID}#{href}" if href[0] is '#'
quote.href = "/#{boardID}/thread/#{href}" # Fix pathnames
continue unless href[0] is '#'
quote.href = Build.path boardID, threadID, href[2..]
container
@ -236,7 +241,7 @@ Build =
$.el 'a',
className: 'summary'
textContent: text.join ' '
href: "/#{boardID}/thread/#{threadID}"
href: Build.path boardID, threadID
thread: (board, data) ->
Build.spoilerRange[board] = data.custom_spoiler

View File

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

View File

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

View File

@ -587,9 +587,9 @@ QR =
QR.cooldown.set {req, post, isReply, threadID}
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
"/#{g.BOARD}/thread/#{threadID}#p#{postID}"
Build.path g.BOARD.ID, threadID, postID
if URL
if Conf['Open Post in New Tab']
$.open URL

View File

@ -49,7 +49,7 @@ QuoteBacklink =
buildBacklink: (quoted, quoter) ->
frag = QuoteBacklink.frag.cloneNode true
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
if quoter.isDead
$.addClass a, 'deadlink'

View File

@ -40,7 +40,7 @@ Quotify =
# Don't add 'deadlink' when quotifying in an archived post,
# and we don't know if the post died yet.
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'
textContent: quote
$.extend a.dataset, {boardID, threadID: post.thread.ID, postID}