Tuesday | 30 APR 2024
[ previous ]
[ next ]

Incoming Links

Title:
Date: 2024-01-04
Tags:  blog

A very messy implementation of incoming links. I need to redo this but for now I'll describe how I implemented this version.

I want each blog post to show any posts that have reference to the current post. This means that I have to search my blog for any links to the current page and display them.

I could do the search programmatically but I'd rather lean on the database itself and use the SEARCH function directly. Unfortunately it's only available by shelling out to TCL. I use the EXECUTE statement below to shell out and I do a search against my blog. I load in the value to search using the DATA statement.

I do the echo off and echo on as the SEARCH command outputs things by default. This is logic that I actually use in [NSH] .

Once the search is finished, I loop over the active list if it's available and read in the markdown to generate the URL.

In [universe] I can do a SELECT statement and get the title and URL directly whereas in [scarletdme] I can't. I wonder if there's a way to do it but this is a pretty big difference. I need to document this but for now I went the explicit route of reading in the markdown and manually creating the URL.

*
GET.INCOMING.LINKS:NULL
*
   INCOMING.LINKS = ''
*
   CLEARSELECT
*
   SERIES = 'SEARCH BLOG-FILE'
   DATA PAGE.ID : ','
   DATA ''
*
   ECHO OFF
   EXECUTE SERIES CAPTURING RESULTS
   ECHO ON
*
   IF @SELECTED > 0 THEN
*
      LOOP
         READNEXT INC.ID ELSE INC.ID = ''
      UNTIL INC.ID = '' DO
         READ INC.MARKDOWN FROM BLOG.FILE,INC.ID ELSE INC.MARKDOWN = 'Not Found.'
*
         INC.TITLE = INC.MARKDOWN<2>[8,999]
         INC.FILENAME = OCONV(INC.TITLE,'MCL')
         INC.FILENAME = CHANGE(INC.FILENAME,' ','-')
         INC.FILENAME = INC.FILENAME : '.html'
*
         INCOMING.LINKS<-1> = INC.TITLE : @VM : INC.FILENAME
      REPEAT
*
      CLEARSELECT
   END
*
   RETURN
*