User Tools

Site Tools


en:user:sample_macros

Sample Macros

Adding a new page to a Greenstone library

Adding a new static page to Greenstone is relatively simple and involves only customizations to macro files (found in gsdl/macros). (Adding a dynamic page is more difficult and involves adding a new action to the C++ receptionist.)

Lets look at the example of adding a new static page called mypage.

  • Link to the new page from the home page
  • Edit the _content_ macro in home.dm, adding the link where you want it. The link will look something like <p style="background:white;"><a href="_httppagex_(mypage)">My Page</a>.
  • Create the macro file:Create a new file called mypage.dm in gsdl/macros.
  • Tell the library about the new file:Edit gsdl/etc/main.cfg. Add mypage.dm to the macrofiles list

mypage.dm will contain all the content on the page. A basic mypage.dm might look something like the following.

package mypage  

_pagetitle_ {My New page}  
_content_{ This is the content of the page. }

The URL for the new page can be specified internally as _httppagex_(mypage): this maps to your library address with cgi arguments a=p&amp;p=mypage.

If this is not a page that belongs to a collection, you should modify the 'home help prefs' buttons. You may like to add the following to your mypage.dm.

_javalinks_ {_imagehome_ _imagehelp_ _imagepref_ }  
_imagehelp_ {_gsimage_(_home:httppagehomehelp_,_httpiconchelpof_,_httpiconchelpon_,help,_textimagehelp_)}  
_imagepref_ {_gsimage_(_home:httppagehomepref_,_httpiconcprefof_,_httpiconcprefon_,pref,_textimagepref_)}

This will give you the standard home button, and the help and preferences buttons that link to the same pages as those on the home page. Help and preferences are different depending on whether you are in a collection or not.

If you are using the Windows local library server you probably need to restart it for the changes to take effect.

Adding a Language Selection Box to each page

You can do this by editing macros, adding some HTML elements and javascript to the pages.

In style.dm, add the following macro:

_languagescript_ {

function updatelang () \{
 newlang = document.LangForm.l.options[document.LangForm.l.selectedIndex].value;

 href=location.href;
  if (href.match(/&amp;l=[\w\-]+/)) href = href.replace(/&amp;l=[\w\-]+/, "&amp;l=" + newlang);
  else href += "&amp;l=" + newlang;
  location.href= href;
\}
</script>
}

Then add the _languagescript_ macro to the end of the _globalscripts_ macro, i.e.

_globalscripts_{
<script language="javascript" type="text/javascript">
_If_(_pagescriptextra_,_pagescriptextra_)
_imagescript_
_languagescript_
</script>
}

Create a language change form in style.dm or base.dm:

_langselectform_{
<div class=langltr style="float: right;">
 <form name="LangForm" method="get" action="_gwcgi_">
  <select name="l" onchange="updatelang();">
   
  <option value="fr" _If_("_cgiargl_" eq "fr", selected)>French
  </option>
  <option value="en" _If_("_cgiargl_" eq "en", selected)>English
  </option>
  <option value="es" _If_("_cgiargl_" eq "es", selected)>Spanish
  </option>

  </select>
 </form>
</div>
}

Add whichever languages you want to support.

Then you need to add the _langselectform_ to all pages that you want it to appear in. To add it beneath the navigation bar on each collection page, add it just at the end of the _optnavigationbar_ macro in nav_css.dm. Otherwise, you will need to add it to the content macro of each page (or to a macro called from the _content_ macro).

Changing the logo on the front page of the library

You can change the logo ("greenstone digital library software") that appears at the top of the front page of your library by editing the home.dm file in your Greenstone "macros" folder and replacing all instances of "gsdlhead.gif" with the name of your logo image file.

Adding an 'I'm feeling lucky' facility

There is a _useifeellucky_ macro in query.dm;

  • if you set this to "_ifeellucky_" then there will be an "I'm feeling lucky" checkbox in the search form.
  • If you tick this then "&ifl=1" goes into the search URL, and code in the C++ redirects you to the first matching document rather than the normal search results page.

(Thanks Michael)

When you add a footer to Greenstone, the footer will appear directly after the content of the page. So, if there is little content on a page, the footer will not be at the bottom of the browser window.

The following CSS ensure the footer is at the bottom of the page (as shown in the image).

package Style

# will be applied to all pages 
# add css style lines inside the style tags

_collectionspecificstyle_ {
<style type="text/css">

html,
body \{
   margin:0;
   padding:0;
   height:100%;
\}

#page \{
   min-height:100%;
   position:relative;
\}

div.document \{
   padding:10px;
   padding-bottom:70px;   /* Height of the footer */
\}

div.v_list \{
margin-top: 2px;
\}

#footer \{
   text-align:center;
   position:absolute;
   bottom:0;
   width:100%;
   height:70px;   /* Height of the footer */
\}

</style>
}

_footer_ {
_pagefooterextra_
<div id="footer"><div class="divbar">&nbsp;</div><small>Greenstone Digital library<br/>
Copyright 2013
</small></div>_endspacer__htmlfooter_
}

And, if you would like your footer to have text on the left, and a logo on the right (as shown above) use the following code:

package Style

# will be applied to all pages 
# add css style lines inside the style tags

_collectionspecificstyle_ {
<style type="text/css">

html,
body \{
   margin:0;
   padding:0;
   height:100%;
\}

#page \{
   min-height:100%;
   position:relative;
\}

div.document \{
   padding:10px;
   padding-bottom:100px;   /* Height of the footer */
\}

div.v_list \{
margin-top: 2px;
\}

small span \{
color: grey;
font-family: Verdana;
line-height: 18px;
font-size: 1em;
\}

#footer \{
   position:absolute;
   bottom:0;
   width:100%;
   height:100px;   /* Height of the footer */
\}

#footer-text \{
width: 50%;
float: left;
height: 100%; 
position: relative;
\}

#footer-image \{
float: left;
width: 50%:
\}

#footer-image img \{
position: absolute;
bottom: 30px;
right: 0;
height:50px;
\}
</style>
}

_footer_ {
_pagefooterextra_
<div id="footer"><div class="divbar">&nbsp;</div><div id="footer-text"><small>Greenstone Digital Library<br/>
Copyright 2013
</small></div><div id="footer-image"><img src="_httpcollection_/images/logo.jpg"/></div></div>_endspacer__htmlfooter_
}

Analytics and hit tracking in Greenstone

Contributed to the mailing list by Yvan Arnaud.

Justin Cooper asked:

Does anyone have experience with setting up website analytics and hit tracking for a Greenstone library? It seems like the way each page is created dynamically would complicate this a little bit, but I'm wondering if anyone has tried to track for example what are more common search terms or which browsing classifiers are utilized more often. I didn't find any tutorials on this topic.

Yvan Arnaud responded with the following suggestions:

I tried Piwik for Greenstone web analytics (http://piwik.org). It's an open source php/mysql web application so you can freely install it on any web server. Have a look to the online documentation to know how to install it on your own server.

Basically, you have to add a javascript code in your pages. The easiest way, I think, is to edit the macro style.dm (in greenstone/macros folder).

You will have to modify the following block :

_htmlfooter_ {
</body>
</html>
}

with something like :

_htmlfooter_ {


<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() \{
    var u=(("https:" == document.location.protocol) ? "https" : "http")
+ "://myserver/piwik/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "5"]);
    var d=document, g=d.createElement("script"),
s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js";
s.parentNode.insertBefore(g,s);
  \})();
</script>
<!-- End Piwik Code -->

</body>
</html>
}

Of course you will replace ://myserver/piwik with your own piwik url.

I think you could do something similar with other web analytics tools like Google Analytics or Open Web Analytics.

en/user/sample_macros.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1