mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Wikify hashtags
This commit is contained in:
parent
710e51fe04
commit
06520c8994
@ -76,7 +76,7 @@ TwitterArchivist.prototype.loadArchive = async function(options) {
|
||||
var tags = ["$:/tags/Tweet"];
|
||||
// Accumulate the replacements/insertions to the text as an array of {startPos:,endPos:,fnTransform:}
|
||||
var modifications = [];
|
||||
// Mentions
|
||||
// Modifications for mentions
|
||||
var mentions = [];
|
||||
$tw.utils.each(tweet.tweet.entities.user_mentions,function(mention) {
|
||||
var title = "Tweeter - " + mention.id_str;
|
||||
@ -90,8 +90,8 @@ TwitterArchivist.prototype.loadArchive = async function(options) {
|
||||
name: mention.name
|
||||
});
|
||||
modifications.push({
|
||||
startPos: mention.indices[0],
|
||||
endPos: mention.indices[1],
|
||||
startPos: parseInt(mention.indices[0],10),
|
||||
endPos: parseInt(mention.indices[1],10),
|
||||
fnTransform: function(text) {
|
||||
return "<$link to=\"" + title + "\">" +
|
||||
$tw.utils.htmlEncode(text.substring(mention.indices[0],mention.indices[1])) +
|
||||
@ -99,43 +99,61 @@ TwitterArchivist.prototype.loadArchive = async function(options) {
|
||||
}
|
||||
});
|
||||
});
|
||||
// URLs
|
||||
// Modifications for URLs
|
||||
$tw.utils.each(tweet.tweet.entities.urls,function(urlInfo) {
|
||||
modifications.push({
|
||||
startPos: urlInfo.indices[0],
|
||||
endPos: urlInfo.indices[1],
|
||||
startPos: parseInt(urlInfo.indices[0],10),
|
||||
endPos: parseInt(urlInfo.indices[1],10),
|
||||
fnTransform: function(text) {
|
||||
return "<a href=\"" + $tw.utils.htmlEncode(urlInfo.expanded_url) + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
|
||||
return "<a href=\"" + urlInfo.expanded_url + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
|
||||
$tw.utils.htmlEncode(urlInfo.display_url) +
|
||||
"</a>";
|
||||
}
|
||||
});
|
||||
});
|
||||
// Modifications for hashtags
|
||||
$tw.utils.each(tweet.tweet.entities.hashtags,function(hashtag) {
|
||||
var title = "#" + hashtag.text;
|
||||
tags.push(title);
|
||||
wiki.addTiddler({
|
||||
title: title,
|
||||
hashtag: hashtag.text,
|
||||
tags: "$:/tags/Hashtag"
|
||||
});
|
||||
modifications.push({
|
||||
startPos: parseInt(hashtag.indices[0],10),
|
||||
endPos: parseInt(hashtag.indices[1],10),
|
||||
fnTransform: function(text) {
|
||||
return "<$link to=\"" + title + "\">" +
|
||||
"#" + $tw.utils.htmlEncode(hashtag.text) +
|
||||
"</$link>";
|
||||
}
|
||||
});
|
||||
});
|
||||
// Sort the modifications by start position
|
||||
modifications.sort(function(a,b) {
|
||||
return a.startPos - b.startPos;
|
||||
});
|
||||
// Apply the modifications in reverse order
|
||||
var rawText = tweet.tweet.full_text,
|
||||
posText = rawText.length,
|
||||
posText = 0,
|
||||
chunks = [];
|
||||
for(var modificationIndex=modifications.length-1; modificationIndex>=0; modificationIndex--) {
|
||||
var modification = modifications[modificationIndex];
|
||||
// Process any text after the modification
|
||||
if(posText > modification.endPos) {
|
||||
chunks.push($tw.utils.htmlEncode(rawText.substring(modification.endPos,posText)));
|
||||
$tw.utils.each(modifications,function(modification) {
|
||||
// Process any text before the modification
|
||||
if(modification.startPos > posText) {
|
||||
chunks.push($tw.utils.htmlEncode(rawText.substring(posText,modification.startPos)));
|
||||
}
|
||||
// Process the modification
|
||||
chunks.push(modification.fnTransform(rawText));
|
||||
// Adjust the position
|
||||
posText = modification.startPos;
|
||||
}
|
||||
posText = modification.endPos;
|
||||
});
|
||||
// Process any remaining text
|
||||
if(posText > 0) {
|
||||
chunks.push($tw.utils.htmlEncode(rawText.substring(0,posText)));
|
||||
if(posText < rawText.length) {
|
||||
chunks.push($tw.utils.htmlEncode(rawText.substring(posText)));
|
||||
}
|
||||
// Concatenate the chunks and replace newlines with <br>
|
||||
var text = chunks.reverse().join("").replace("\n","<br>");
|
||||
var text = chunks.join("").replace("\n","<br>");
|
||||
// Create the tweet tiddler
|
||||
var tiddler = {
|
||||
title: "Tweet - " + tweet.tweet.id_str,
|
||||
|
@ -206,6 +206,17 @@ No Twitter Archives are currently loaded
|
||||
|
||||
\define show-tweeter-mentions()
|
||||
<$list filter="[tag[$:/tags/Tweet]tag<currentTiddler>]">
|
||||
<$macrocall $name="show-tweet" archive=<<currentTiddler>> title=<<currentTiddler>>/>
|
||||
<$macrocall $name="show-tweet" title=<<currentTiddler>>/>
|
||||
</$list>
|
||||
\end
|
||||
|
||||
\define show-hashtag()
|
||||
<a href={{{ [{!!user_id}addprefix[https://twitter.com/intent/user?user_id=]] }}} rel="noopener noreferrer" target="_blank">View on Twitter</a>
|
||||
<$macrocall $name="skinny-tabs" tabNames="show-hashtag-tweets" tabCaptions="Tweets" defaultTab="show-hashtag-tweets" state=<<qualify "$:/state/skinny-tabs/hashtag-tweets">>/>
|
||||
\end
|
||||
|
||||
\define show-hashtag-tweets()
|
||||
<$list filter="[tag[$:/tags/Tweet]tag<currentTiddler>]">
|
||||
<$macrocall $name="show-tweet" title=<<currentTiddler>>/>
|
||||
</$list>
|
||||
\end
|
||||
|
@ -0,0 +1,3 @@
|
||||
title: $:/plugins/tiddlywiki/twitter-archivist/template/hashtag
|
||||
|
||||
<<show-hashtag>>
|
@ -5,3 +5,4 @@ list-before:
|
||||
[tag[$:/tags/Tweet]then[$:/plugins/tiddlywiki/twitter-archivist/template/tweet]]
|
||||
[tag[$:/tags/TwitterArchive]then[$:/plugins/tiddlywiki/twitter-archivist/template/archive]]
|
||||
[tag[$:/tags/Tweeter]then[$:/plugins/tiddlywiki/twitter-archivist/template/tweeter]]
|
||||
[tag[$:/tags/Hashtag]then[$:/plugins/tiddlywiki/twitter-archivist/template/hashtag]]
|
||||
|
Loading…
Reference in New Issue
Block a user