0

我正在尝试将 Disqus 添加到我正在写的博客中。要处理 Seaside 会话,我需要向 JS 添加一个唯一的 discus_identifier 或 disqus_url。我覆盖了组件的 #script 方法,但它只能返回一个字符串文字。

我看到两个选项:

  1. 动态生成 JS,将其保存到文件中,然后将该文件加载到我的组件中。
  2. 为每个博客条目添加一个永久链接。

有没有更简单的方法?或者这些方法中的一种(或两种)容易做到吗?我是 Smalltalk 和 Seaside 的新手,不确定如何完成这两件事。

4

2 回答 2

1

是的,有一种更简单的方法。您可以直接在#script 方法中生成正确的Discus JS 代码。它应该返回一个字符串文字,但您可以即时创建此字符串。例如,通过使用 WriteStream。

您的博客条目还需要一个永久链接。您可以使用 #initialRequest: 方法来处理这些永久链接。

于 2011-01-26T20:44:50.380 回答
1

动态的javascript东西

如果我是对的,那也是你会遇到的那种情况,比如转发按钮。(这是我手头可以为您提供的示例)。

我在博客中所做的是一个名为 BITRetweet 的专门海边组件,您可以使用永久链接(以及用户名和样式偏好)进行配置。忘记文件的东西(只会使事情复杂化),一切都在进行中。它用这个渲染:

BITRetweet>>renderContentOn: html

html script with: self customizedJavascript.
html script url: self buttonJavascriptSource.

BITRetweet>>customizedJavascript

| script |

script := JSScript new.

script add: (('"',self permalink,'"') asJSObject assignTo: 'tweetmeme_url').

isCompact ifTrue:[
    script add: ('"compact"' asJSObject assignTo: 'tweetmeme_style')].

script add: (('"',username,'"') asJSObject assignTo: 'tweetmeme_source').
script add: (('"',shortener,'"') asJSObject assignTo: 'tweetmeme_service').

^ script 

BITRetweet>>>buttonJavascriptSource

"Answers the url to the source of the script for the button.
See: 
http://help.tweetmeme.com/2009/04/06/tweetmeme-button/"

^ 'http://tweetmeme.com/i/scripts/button.js'

and finally a little hack for String, like this:

String>>asJSObject

^ JSObject new alias: self

使用固定链接

对于永久链接部分,有两件事:

  1. 生成它
  2. 使用它(使应用程序在请求附带时做出反应)

对于 1,您可以执行以下操作:

PostComponent>>updateUrl: anUrl

super updateUrl: anUrl.

anUrl addToPath: model asURLNice

Post>>asURLNice

"Answers the receiver in an (destructive) encoded 
way which is url friendly"

^ String streamContents: [:stream|
    self do:[:char|
        char isSeparator 
            ifTrue:[stream nextPut: $-]
            ifFalse:[
                char isAlphaNumeric ifTrue:[
                    stream nextPut: char asLowercase asNonDiacritical]]]]

对于 2 ,您必须在主应用程序组件中执行以下操作:

BlogApplication>>initialRequest: aRequestOrNil

| paths |

super initialRequest: aRequestOrNil.

aRequestOrNil ifNil:[^ nil].

(aRequestOrNil url asString endsWith: '/sitemap.xml') ifTrue:[
    ^ self respondSitemap].

paths := aRequestOrNil url path.
paths size < 2 ifTrue:[^nil].

(Post atURLTitle: paths last) ifNotNilDo: [:value | 
    ^ self readPost:  value].

活生生的例子

您可以在我的博客选择性创造力中看到所有这些, asNonDiacritical 对我来说是必需的,因为我的博客是三语的,但如果您需要,可以在squeaksource中使用 DiacriticalSupport

玩得开心

o/

于 2011-02-06T20:20:09.207 回答