From f8480a16125375d5fd5af285c5005b96d79457ce Mon Sep 17 00:00:00 2001 From: pi-ux-ce Date: Wed, 21 Jan 2026 14:45:27 +0000 Subject: [PATCH] Update XML_Parser_wikijsCreator --- XML_Parser_wikijsCreator | 111 +++++++++++++++++++++++++++++++++++++++ parse-xml | 6 --- 2 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 XML_Parser_wikijsCreator delete mode 100644 parse-xml diff --git a/XML_Parser_wikijsCreator b/XML_Parser_wikijsCreator new file mode 100644 index 0000000..60a53f6 --- /dev/null +++ b/XML_Parser_wikijsCreator @@ -0,0 +1,111 @@ +<# +We will need to add at the start of the document and at the end +#> + +Function CreateWikijsPage { + param ( $InputPagePath , $TitleOfTheArticle) + +$GraphQLEndpoint = "https://wikijs.tryton.geeraert.eu/graphql" + +$AccessToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGkiOjIsImdycCI6MSwiaWF0IjoxNzY4OTkzNzA4LCJleHAiOjE4MDA1NTEzMDgsImF1ZCI6InVybjp3aWtpLmpzIiwiaXNzIjoidXJuOndpa2kuanMifQ.ivUT8LUM-vul3JykAUPp4dnldxat8-kUvrsjQ51tuoE6dXJLgsZm-FYzGVQBRRMpZXbWIDjy0wuPJwEaZxMywN2O2ys5UrmIO5MxCydV8zeiPooPHKOhtU6rbAPGdICHRjpneiIx5dmahzGN2FDzqhIeR4_H2pioYWLih1ohlmDmUGsTpcJgSY73O0_xDa_gnVwAdsmwDRqwZSdd04ZCCYpzBIkR9YR1kPtxtX9UHonWRAYvKJckCQYUjTiHUWU1pBKnHWsxsygMqgj56rRufs4C37i_WGKBKw-NXjRiS6Z32oTBDOL9Rv_YMhmhwHLb3Hb_eEtl2nXYPelEXxGWUw" + +# Define the new page details +#$NewPagePath = "/Work/Deployments/Tutorial/my_new_article" +$NewPagePath = $InputPagePath +$PageTitle = "My New Article" +$PageContent = @' +# This is a new article + +Created via PowerShell and GraphQL. +'@ + +$Headers = @{ + "Content-Type" = "application/json" + "Authorization" = "Bearer $AccessToken" +} + +$GraphQLMutation = @' +mutation CreatePage { + pages { + create( + content: "This is the content of the new page created via PowerShell.", + description: "", + editor: "markdown", + isPublished: true, + isPrivate: false, + locale: "en", + path: "InputPagePath", + tags: [], + title: "titleofthearticle" + ) { + responseResult { + succeeded + errorCode + slug + message + } + page { + id + path + title + } + } + } +} +'@ + + +$GraphQLMutation = $GraphQLMutation.Replace("InputPagePath", $InputPagePath) +$GraphQLMutation = $GraphQLMutation.Replace("titleofthearticle", $TitleOfTheArticle) + + +$Body = @{ + query = $GraphQLMutation +} | ConvertTo-Json -Depth 3 + +try { + $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Method Post -Headers $Headers -Body $Body + $result = $response.data.pages.create + if ($result.responseResult.succeeded) { + Write-Host "✅ Page created successfully!" + $result.page | Format-Table id, title, path + } else { + Write-Error "❌ Failed: $($result.responseResult.message)" + } +} catch { + Write-Error "GraphQL request failed: $_" +} + +} + +[xml]$cn = Get-Content "C:\Users\pgeeraert\Downloads\export-onenote\Deployments-xml.xml" +#$cn.xml.Section.Page.Name + +$illegal = [string]::join(' ',"'",'+','🛠️',([System.IO.Path]::GetInvalidFileNameChars())) + +foreach ($Section in $cn.xml.Section) { + $section_name = $Section.name + #write-output "Section: $section_name" + $section_name_replaced = $section_name -replace "[$illegal]",'_' + #write-output "Section replaced: $section_name_replaced" + + foreach ($Page in $Section.Page) { + $page_name = $Page.name + #write-output "Page: $page_name" + $page_name_replaced = $page_name -replace "[$illegal]",'_' + #write-output "Page replaced: $page_name_replaced" + + #/Work/Deployments/Tutorial/another-testing" + $path = "/Deployments/$section_name_replaced/$page_name_replaced" + write-output $path + Write-Output $page_name + CreateWikijsPage -InputPagePath $path -TitleOfTheArticle $page_name + #sleep 5 + } +} + + + + + + diff --git a/parse-xml b/parse-xml deleted file mode 100644 index 7181271..0000000 --- a/parse-xml +++ /dev/null @@ -1,6 +0,0 @@ -<# -We will need to add at the start of the document and at the end -#> - -[xml]$cn = Get-Content "C:\Users\pgeeraert\Downloads\export-onenote\Deployments-xml.xml" -$cn.xml.Section.Page.Name \ No newline at end of file