forked from houshuang/folders2web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiki-lib.rb
51 lines (47 loc) · 2.06 KB
/
wiki-lib.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# encoding: UTF-8
$:.push(File.dirname($0))
require 'utility-functions'
require 'bibtex'
require 'citeproc'
require 'appscript'
include Appscript
# clean braces
def cb(text)
# clean braces
text.gsub(/[\{|\}]/,'')
end
# ensure that main refpage exists for a given citekey, taking info from BibDesk (needs to be running,
# maybe replace with taking info from Bibtex file eventually)
def ensure_refpage(citekey,override=false)
if !File.exists?("/wiki/data/pages/ref/#{citekey}.txt") || override
dt = app('Bibdesk')
find = dt.document.search({:for => citekey})
if find == []
growl("File not found", "Cannot find citation #{ARGV[0]} in BibDesk")
exit
end
bib = BibTeX.parse(find[0].BibTeX_string.get.to_s)
bib.parse_names
item = bib[citekey.to_sym]
p item
citation = CiteProc.process(item.to_citeproc, :style => :apa)
p item.class
javascript = "javascript:var MyFrame='<frameset cols=\\'*,*\\'><frame src=\\'/wiki/notes:#{citekey}?do=edit&vecdo=print\\'><frame src=\\'/wiki/clip:#{citekey}?vecdo=print\\'></frameset>';with(document) { write(MyFrame);};return false;\""
citation = "^ Citation |#{cb(citation)} ^ <html><a href=\"#{javascript}\">Sidewiki</a></html>^\n^[[bibdesk://#{citekey}|BibDesk]] | ::: ^ [[skimx://#{citekey}|PDF]] ^ "
text = "h1. #{cb(item[:title])}\n\n#{citation}\n\n<hidden BibTex>\n #{item.to_s}\n</hidden>\n\n{{page>notes:#{citekey}}}\n\nh2. Links here\n{{backlinks>.}}\n\n{{page>clip:#{citekey}}}\n\n{{page>kindle:#{citekey}}}\n\n{{page>skimg:#{citekey}}}"
dwpage("ref:#{citekey}", text, 'Automatically generated from Bibdesk')
end
end
def make_newimports_page(ary)
# b = BibTeX.open("/Volumes/Home/stian/Dropbox/Archive/Bibliography.bib")
# b.parse_names
#
# out = "h1. Recently imported items\n\n^Note name ^ Note text ^\n"
# ary.each do |citekey|
# item = b[citekey.to_sym]
# cit = CiteProc.process item.to_citeproc, :style => :apa
# out << "| [[:ref:#{item.key}]] | #{cit}|\n"
# end
#
# File.open('/wiki/data/pages/bib/recent_imports.txt', 'w') {|f| f << out}
end