majkinetor / mm-docs

Documentation system in a docker container using mkdocs, plantuml and many more
GNU General Public License v3.0
18 stars 3 forks source link

Last changed date on each page #6

Closed majkinetor closed 3 years ago

majkinetor commented 5 years ago

The current plugin https://github.com/zhaoterryy/mkdocs-git-revision-date-plugin seems problematic because it requires git to be present during build which might not be general case and also it might be on monorepo which makes paths different then those during build.

Idea is to export dates before the build for all included files and make a plugin that consults this file.

majkinetor commented 5 years ago

Function to get such file:

function Get-GitRevisionDates($Path='.', $Ext, $Skip)
{
    [array] $log = git --no-pager log --format=format:%ai --name-only $Path

    $date_re = "^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d .\d{4}$"
    [array] $dates = $log | Select-String $date_re | select LineNumber, Line

    $files = $log -notmatch "^$date_re$" | ? {
        if (!$_.EndsWith($Ext)) { return }
        foreach ($s in $Skip) { if ($_ -like $s) { return } }
        $_
    } | sort -unique

    $res = @()
    foreach ($file in $files) {
        $iFile = $log.IndexOf($file) + 1
        $fDate = $dates | ? LineNumber -lt $iFile | select -Last 1
        $res += [PSCustomObject]@{ File = $file; Date = $fDate.Line }
    }

    $res | sort Date -Desc
}
majkinetor commented 3 years ago

Implemented:

image