Metadata tutorial

Aug 01, 2007 18:37

Okay so apparently my metadata post was deleted, anyway here it is again:

How to get this for your journal:


You need a paid account, S2, Flexible Squares but works for other themes too, usage of layers.
I didn't create the code, all credit goes to kunzite1 and kentucka, I just edited it.


1. You must have a theme layer where you can put the code. If you're already using a theme layer, nevermind this step. If you're not using a theme layer, create one here.

2. Okay, you know the layerinfo at the top of your layer right? Mine says this:

layerinfo "type" = "theme";
layerinfo name = "LayerName";
set tags_aware = true; # this is needed to keep S2 from meshing the tags simply after the entry
set text_tags = "Tags:";

Copy and paste the parts starting from "set tags_aware".

3. If you have a themelayer it might be possible that you've edited it and put other chunks of code in there. If you have, find this code:
function Entry::print_metadata()
and delete it. If you haven't edited your theme layer at all, ignore this step.

4. Copy this in your theme layer. Doesn't matter where, as long as it's after the layerinfo.

function Entry::print_metadata() {
var string tags_header = "
"; # text for tags header, "Current Tags"
var string tags_joiner = " "; # text for tags joiner, ":"
var string tags_sep = ", "; # text for tags separator, ", "
var bool show_edit_tags_link = false; # set to true if you want edit tags link as tags header

var string currents_open = """

"""; # html for opening of currents container
var string currents_close = """"""; # html for closing of currents container

var bool loc_after_mood = false; # set to true to print location after mood
var bool vanilla_loc = false; # set to true to delinkify location

# if you need data specific to the meta to be in these strings you'll have to set those individually down further
# one example is provided with meta_label_open
var string meta_label_open = ""; # html for opening of metadata label
var string meta_label_close = """ """; # html for closing of metadata label
var string meta_val_open = ""; # html for opening of metadata value
var string meta_val_close = """"""; # html for closing of metadata value

var Link edit_tags = $this->get_link("edit_tags"); # helper var to see if remote user can edit tags

if ((size $.metadata > 0) or ((size $.tags > 0) and ($*tags_aware))){
if($.metadata{"mood"} == "" and $loc_after_mood) {
# if we're printing loc after mood but we have no mood, set loc_after_mood to false
$loc_after_mood = false;
}
var string currents = ""; # make var for printing
$currents = $currents_open; # add opening of currents container

if(defined $.mood_icon) {
var Image i = $.mood_icon;
$currents = $currents + """
""";
}

foreach var string k ($.metadata){ # step thru metadata
var string text = $k; # set text to key
var string val = $.metadata{$k}; # get val
if ($k == "mood"){ # if mood, set text to mood property
$text = """
""";
}
elseif ($k == "music") { # if music, set text to music property
$text = """
""";
} elseif ($k == "location") { # if location, set text to loc variable
$text = """
""";
if($vanilla_loc) { # if vanilla loc, striphtml() it
$val = striphtml($val);
}
}
if(not ($k == "location" and $loc_after_mood)) {
# if we're doing loc right now and printing loc after mood, skip it
# if we're doing loc right now and we're not printing loc after mood, print it now
# if we're not doing loc right now, print this piece of meta

# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";

# add the meta
$currents = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
}

if($k == "mood" and $loc_after_mood) {
# if we just now did the mood and we're printing loc after mood, print the loc
$k = "location"; # set meta key to "location"
$text = $*text_meta_location; # set text to loc variable
$val = $.metadata{$k}; # get val

# if we have a loc, do stuff
if($val != "") {

# if vanilla loc, striphtml() it
if($vanilla_loc) {
$val = striphtml($val);
}

# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";

# add the meta
$currents = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
}
}
}
if ((size $.tags > 0) and $*tags_aware) {
var string k = "tags"; # set key to "tags"

# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";

var int tcount = 0; # set counter for tags
if($edit_tags.url != "" and $show_edit_tags_link) { # if remote user can edit tags, let's give them a link
$tags_header = """ $tags_header""";
}

# add text, open val container
$currents = $currents + """$meta_label_open$tags_header$tags_joiner$meta_label_close$meta_val_open""";

# build tag list
foreach var Tag t ($.tags) {
$currents = $currents + """ $t.name""";
$tcount++;

# if we haven't hit the last tag, add a separator
if ($tcount != size $.tags) { $currents = $currents + $tags_sep; }
}

# close val container
$currents = $currents + $meta_val_close;
}

if(defined $.mood_icon) {
$currents = $currents + """""";
}

# close currents container
$currents = $currents + $currents_close;

# print currents
println "$currents";
}
}

5. Compile.
Please save the images to your own server!

Hope it's helpful, once again I didn't create the code, no need to credit. If you have any questions, feel free to ask! I might not be able to answer them because I'm nowhere near an expert on layers and such. If I can't answer your question, try s2flexisquares.

coding: livejournal

Previous post Next post
Up