browse by category or date

consoleA few months ago I was given a project to maintain a corporate website. This website was previously hosted in a CMS in remote site. When I received the CD containing the project files, it was already in ‘offline’ website format. It means all files are now static HTML. I suspect that it generated using those website downloaders (Offline Explorer, etc.).

The problem with static HTML website is there are many duplicates of information. One news article will show up as many files that located in different folders. It could be under News folder, News Archive folder, Tags folder, etc.

It means my task will become a boring headache, since I will need to add content, add it to the respective folders, and manually update all the linkage regularly.

So I came out with a simple program to help me generating the content, upload the attachment and to update the linkage. This is when I hit the problem. Because most of the time, a news article will contain attachments. The attachments will be stored under Attachments folder, but the pages that linked to that attachment are scattered all over the place. I also need to update the β€˜index’ files of each category (Archive by Year, Archive by Tag, Archive by Category, etc.)

Solution

Instead of reinventing the wheel, I asked Google to find me the wheel πŸ˜€ David M. Howard has solved this problem 9 years ago πŸ™‚ Thank You David!

His solution was written in Java, I just need to convert it to .NET and tweaked it a little without any difficulties.

Result

The output of the test program are as follows:

Home: C:boot.ini
Remote: C:WINDOWSsystem32driversetchosts
Relative Path: WINDOWSsystem32driversetchosts

Home: C:WINDOWSsystem32driversetchosts
Remote: C:boot.ini
Relative Path: ……..boot.ini

Home: C:WINDOWSsystem32driversetchosts
Remote: I:PVSW.LOG
Relative Path: I:PVSW.LOG

Source Code

'Filename: MyPath.vb
Imports System.IO
Imports System.Collections

Public Class MyPath
    Public Shared Function getRelativePath(ByVal home As String, ByVal remote As String) As String
        Return getRelativePath(New FileInfo(home), New FileInfo(remote))
    End Function
    Public Shared Function getRelativepath(ByVal home As String, ByRef remote As FileInfo) As String
        Return getRelativepath(New FileInfo(home), remote)
    End Function
    Public Shared Function getRelativePath(ByRef home As FileInfo, ByVal remote As String) As String
        Return getRelativePath(home, New FileInfo(remote))
    End Function

    Public Shared Function getRelativePath(ByRef home As FileInfo, ByRef remote As FileInfo) As String
        Dim homepathList As New ArrayList
        Dim remotePathList As New ArrayList
        Dim result As String = ""

        If ((home.Exists And remote.Exists) Or home.Directory.Exists Or remote.Directory.Exists) Then
            'initialize the paths
            initPathList(home.Directory, homepathList)

            If remote.Attributes = FileAttributes.Directory Then
                initPathList(remote.Directory, remotePathList)
            Else
                initPathList(remote, remotePathList)
            End If

            Dim ihome As Integer = homepathList.Count - 1
            Dim iremote As Integer = remotePathList.Count - 1

            'Do we have common parent
            If Not homepathList(ihome).Equals(remotePathList(iremote)) Then
                Return remote.FullName
            End If

            'remove common parent            
            While (ihome >= 0 And iremote >= 0)
                If homepathList(ihome).Equals(remotePathList(iremote)) Then
                    ihome -= 1
                    iremote -= 1
                Else
                    Exit While
                End If
            End While

            'Add relative path
            While ihome >= 0
                result &= ".." & System.IO.Path.DirectorySeparatorChar.ToString()
                ihome -= 1
            End While

            'Combine relative path result with the remote 

            While iremote > 0
                result &= remotePathList(iremote).ToString() & System.IO.Path.DirectorySeparatorChar.ToString()
                iremote -= 1
            End While
            result &= remotePathList(iremote).ToString()
        Else
            If Not home.Exists Then
                Throw New Exception(home.FullName & " is not exist!")
            End If
            If Not remote.Exists Then
                Throw New Exception(remote.FullName & " is not exist!")
            End If
        End If
        Return result
    End Function
    Public Shared Sub initPathList(ByRef f As FileInfo, ByRef ar As ArrayList)
        ar.Add(f.Name)
        initPathList(f.Directory, ar)
    End Sub
    Public Shared Sub initPathList(ByRef dir As DirectoryInfo, ByRef ar As ArrayList)
        ar.Add(dir.Name)
        While Not dir.Parent Is Nothing
            dir = dir.Parent
            ar.Add(dir.Name)
        End While
    End Sub
End Class
'Filename: testMyPath.vb
Imports System.IO

Module Module1

    Sub Main()
        While True
            Console.Write("Home: ")
            Dim homePath As String = Console.ReadLine()
            Console.Write("Remote: ")
            Dim remotePath As String = Console.ReadLine()
            Try
                Console.WriteLine("Relative Path: " & MyIO.MyPath.getRelativePath(homePath, remotePath))
            Catch ex As Exception
                Console.WriteLine("ERROR: " & ex.ToString())
            End Try
            Console.WriteLine()
        End While
    End Sub

End Module

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

An interesting entry show up in Akismet’s spam list:

kelly

It is interesting that it end-up blocked by Akismet, even though it doesn’t mention any product, or linking to a questionable website, it simply links to Kelli’s Wikipedia page. Earlier discussion mentioned that it was the email address that causing the block.

Who will benefit from such action? Will Kelli Garner became more famous by gaining notoriety as a spammer? One could not forget how Paris Hilton become everyday conversations because of her sex tape leaked. So yeah, you can become famous by gaining notoriety. The more notorious you are, the more publicity you’ll get. Bad publicity, good publicity, all kinds of publicity, there is no such thing as bad publicity.

Or could it be someone else profited? If yes, in what way? Or is it just someone who is trying to be her biggest fan by dedicating her/his life promoting Kelli?

Another possible explanation is someone actually have planted something malicious at her Wiki page, which will be triggered whenever a person visit that page? Which is to me, a very likely explanation. Is this a Zero Day attack?

Anyway, the spam origin was from server which is apparently located at Prague, Czech Republic.

217.31.51.77

PS: This post is now officially unintentionally became part of the publicity machine.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Yesterday, I visited Ainun’s wedding party at An-Nahdah Mosque. It was my first time attending a wedding party that is held in a Mosque (apology to Rahman and Ratih for missing your wedding party, I was with my family in Bali that time :)).

The atmosphere was great, the food was delicious, but one thing that struck my mind that day was the prayer that was given by the Habib (I didn’t get his full name) to Ainun and his Wife. He prayed that Ainun and Yanti will have a barokah life. Barokah as in:

  1. Even when your money is not much, you still found it enough
  2. Even when what you have is not many, you still found it sufficient
  3. Even when you have a little time, you can do many things
  4. Even when you are given a short life, you can achieve so many things

“Houston, we have a problem!”

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: