Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Add wikilink parsing plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mdcfe committed Mar 25, 2018
1 parent 8730adc commit 3de6417
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 72 deletions.
20 changes: 20 additions & 0 deletions docute-wikilink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const re = /\[\[([\w\s]+)\]\]/g; // [[SupaHam]]
const rePiped = /\[\[([\w\s]+)(?:\|)(\w+)\]\]/g; // [[Pineapple|MD678685]]

const replacement = `<a class="router-link" href="#/$uri">$text</a>`;

function docuteWikilink(context) {
context.beforeParse(content => {
/*
const parsed = content.replace(re, `[$1]($1)`)
.replace(rePiped, "[$1]($2)");
*/
const parsed = content.replace(re, (match, p1) =>
replacement.replace("$text", p1).replace("$uri", p1.replace(" ", "-")))
.replace(rePiped, (match, p1, p2) =>
replacement.replace("$text", p1).replace("$uri", p2));

console.log(content, parsed);
return parsed;
});
};
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/[email protected]/components/prism-groovy.js"></script>
<script src="https://unpkg.com/[email protected]/components/prism-java.js"></script>
<script src="docute-wikilink.js"></script>
<script src="vue-dlpage.js"></script>
<script src="main.js"></script>
</body>
</html>
76 changes: 4 additions & 72 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,7 @@ const mirrorCI = "https://ci.akpmakes.tech/job/EssentialsX/";

axios.defaults.baseURL = mirrorCI; // ender.zone doesn't allow CORS

const landing = {
html: `
<transition name="fadein">
<div id="landing" class="main content markdown-body">
<p><img src="https://camo.githubusercontent.com/9ad178e5cf76a372d6aaee8bbdf13485fbc1d51b/68747470733a2f2f692e696d6775722e636f6d2f435034535a70422e706e67"></img></p>
<p><i>This is not an official EssentialsX site.</i></p>
<h2>Download EssentialsX</h2>
<section>
<p v-if="buildNo">The latest version of EssentialsX is <b>{{build}}</b>.</p>
<p v-if="failed" class="warning">Could not retrieve information about the latest version.</p>
<table v-if="buildNo">
<tr>
<th>Plugin</th>
<th>Main</th>
<th>Mirror</th>
</tr>
<tr v-for="plugin in plugins" :key="plugin.name">
<td>{{ plugin.name }}</td>
<td><a :href="plugin.main">Download</a></td>
<td><a :href="plugin.mirror">Download</a></td>
</tr>
</table>
<button @click="updateInfo">Update</button>
</section>
<h2>Help for EssentialsX</h2>
<section>
<router-link to="/Home">Go to EssentialsX Wiki</router-link>
</section>
</div>
</transition>
`,
component: {
data() {
return {
buildNo: null,
failed: null,
plugins: [],
};
},
computed: {
build() {
return this.buildNo ? `b${this.buildNo}` : "unknown";
},
},
methods: {
updateInfo() {
axios.get("lastSuccessfulBuild/api/json")
.then(response => {
this.buildNo = response.data.id;
this.plugins = response.data.artifacts.map(artifact => {
return {
name: `EssentialsX ${artifact.displayPath.match(/EssentialsX([A-Za-z]*)/)[1]}`,
main: `${mainCI}lastSuccessfulBuild/artifact/${artifact.relativePath}`,
mirror: `${mirrorCI}lastSuccessfulBuild/artifact/${artifact.relativePath}`,
};
});
this.failed = null;
}, error => {
if (error.response) {
this.failed = error.response.data;
} else {
this.failed = error.message;
}
}
);
}
},
mounted: function () {
this.updateInfo();
}
},
}
const landing = window.dlPage;

docute.init({
url: "https://raw.githubusercontent.com/wiki/EssentialsX/Essentials/",
Expand Down Expand Up @@ -103,5 +32,8 @@ docute.init({
{ title: "Issue Tracker", path: "https://github.com/EssentialsX/Essentials/issues" },
{ title: "Discord", path: "/Discord-Rules" }
],
plugins: [
docuteWikilink,
],
debug: true
});
74 changes: 74 additions & 0 deletions vue-dlpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const component = {
html: `
<transition name="fadein">
<div id="landing" class="main content markdown-body">
<p><img src="https://camo.githubusercontent.com/9ad178e5cf76a372d6aaee8bbdf13485fbc1d51b/68747470733a2f2f692e696d6775722e636f6d2f435034535a70422e706e67"></img></p>
<p><i>This is not an official EssentialsX site.</i></p>
<h2>Download EssentialsX</h2>
<section>
<p v-if="buildNo">The latest version of EssentialsX is <b>{{build}}</b>.</p>
<p v-if="failed" class="warning">Could not retrieve information about the latest version.</p>
<table v-if="buildNo">
<tr>
<th>Plugin</th>
<th>Main</th>
<th>Mirror</th>
</tr>
<tr v-for="plugin in plugins" :key="plugin.name">
<td>{{ plugin.name }}</td>
<td><a :href="plugin.main">Download</a></td>
<td><a :href="plugin.mirror">Download</a></td>
</tr>
</table>
<button @click="updateInfo">Update</button>
</section>
<h2>Help for EssentialsX</h2>
<section>
<router-link to="/Home">Go to EssentialsX Wiki</router-link>
</section>
</div>
</transition>
`,
component: {
data() {
return {
buildNo: null,
failed: null,
plugins: [],
};
},
computed: {
build() {
return this.buildNo ? `b${this.buildNo}` : "unknown";
},
},
methods: {
updateInfo() {
axios.get("lastSuccessfulBuild/api/json")
.then(response => {
this.buildNo = response.data.id;
this.plugins = response.data.artifacts.map(artifact => {
return {
name: `EssentialsX ${artifact.displayPath.match(/EssentialsX([A-Za-z]*)/)[1]}`,
main: `${mainCI}lastSuccessfulBuild/artifact/${artifact.relativePath}`,
mirror: `${mirrorCI}lastSuccessfulBuild/artifact/${artifact.relativePath}`,
};
});
this.failed = null;
}, error => {
if (error.response) {
this.failed = error.response.data;
} else {
this.failed = error.message;
}
}
);
}
},
mounted: function () {
this.updateInfo();
}
},
};

window.dlPage = component;

0 comments on commit 3de6417

Please sign in to comment.