zillo32 / vosao

Automatically exported from code.google.com/p/vosao
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Enable velocity in Disqus embed code #501

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The following commented out lines, containing two highly recommended fields, 
are in the embed code that is copied into the Disqus plugin options:

    // The following are highly recommended additional parameters. Remove the slashes in front to use.
    // var disqus_identifier = 'unique_dynamic_id_1234';
    // var disqus_url = 'http://example.com/permalink-to-page.html';

disqus_identifier allows the page to be identified, even if the URL changes or 
if the page has multiple URLs.

disqus_url allows the correct permalink to be set.

I think it should be possible to use a velocity command to provide an 
unchangable identifier (is there a command to display a page's internal ID?) 
and the correct URL for these options.

Some good reasons for this:

1. A user might want to change a permalink. If they do so at present, they will 
lose the association of any existing comments with that page.

2. A site can exist at multiple URLs. For example, my site can be accessed from 
http://www.markdarb.com and http://markdarb.appspot.com. However, if I used the 
Disqus problem I would end up with a situation where I had one set of comments 
at one domain but a completely separate set of comments on the other domain.

 I'd like to be sure comments aren't going to be added at one domain but not associated with the right page at the other domain.

3. It's future-proofing the site. If there are some significant changes to a 
site in the distant future (e.g. switching to a new domain or CMS), it will be 
much easier if the comments are tied to an ID.

4. Disqus highly recommends these options. It would be wise to allow users to 
follow their recommendations.

If this suggestion were implemented, I'd be able to provide the options along 
these lines:

    var disqus_identifier = '$page.id';
    var disqus_url = '$page.friendlyURL';

Original issue reported on code.google.com by markd...@gmail.com on 29 Jul 2011 at 4:45

GoogleCodeExporter commented 8 years ago
It just occurred to me that it might be possible to put these values in 
directly using JavaScript (since this is JavaScript code). If that is the case, 
can someone please let me know?

Original comment by markd...@gmail.com on 29 Jul 2011 at 4:58

GoogleCodeExporter commented 8 years ago
1. We need to have unique page id.

Vosao CMS uses internally URL as a unique page identifier.

$page.id will not work as it is changed if you create new page version.

I suggest to use page attribute for holding page key.

2. We can use JavaScript to provide Disqus with page id. 
This can be done using page template where you define javascript id variable 
and then use it in Disqus code snippet.

In page template:

<script type="text/javascript">var pageGUID = '$page.attribute.guid';</script> 

(create page attribute "guid")

And in Disqus:

var disqus_identifier = pageGUID;

Original comment by kinyelo@gmail.com on 29 Jul 2011 at 8:49

GoogleCodeExporter commented 8 years ago
Thanks very much for your help.

I didn't like the idea of having to manually specify the ID for every page, so 
I've come up with a compromise solution. It defaults to the Friendly URL (e.g. 
"/blog/my-first-blog-entry") as the Disqus ID, but this can be overridden by 
adding a disqusID attribute to a page. That way if anything gets moved around 
in the future, the existing ID can be manually kept the same, but otherwise 
everything can be left to handle itself automatically.

In the <head> section of the template, put:

<script type="text/javascript">
    if("$page.attribute.disqusID"=="$"+"page.attribute.disqusID") {
        var disqusID = "$page.friendlyURL";
    } else {
        var disqusID = "$page.attribute.disqusID";
    }
</script>

In the Disqus plugin options, put:

    var disqus_identifier = disqusID;

Still, I wonder if it would be realistic and helpful to add functionality like 
this to the Disqus plugin out of the box?

Original comment by markd...@gmail.com on 29 Jul 2011 at 10:06

GoogleCodeExporter commented 8 years ago
I've gone a little bit further again. Just posting the code in case its of use 
to anyone else. This time I've got the main domain that I want to ensure is 
used for the permalink coded in. Not essential, but at least it means both 
recommended fields are being provided.

In the template (note that www.yourdomain.com needs replacing with your domain):

<script type="text/javascript">
    if("$page.attribute.disqusID"=="$"+"page.attribute.disqusID") {
        var disqusID = "$page.friendlyURL";
    } else {
        var disqusID = "$page.attribute.disqusID";
    }
    var fullPermalink = "http://www.yourdomain.com" + "$page.friendlyURL";
</script>

In the embedded Disqus code:

    var disqus_identifier = disqusID;
    var disqus_url = fullPermalink;

Original comment by markd...@gmail.com on 29 Jul 2011 at 11:31