Skip to content

Commit

Permalink
fixed missing base
Browse files Browse the repository at this point in the history
fixed svg on load event
  • Loading branch information
wassfila committed May 18, 2024
1 parent 7100956 commit adf70d7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
1 change: 0 additions & 1 deletion integrations/create_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {pages_list_to_tree} from './process_menu.js'
import {getDocuments} from 'content-structure'
import {createHash} from 'crypto'
import { config } from '../config.js';
import { readdir } from 'fs/promises';
import {dirname} from 'path';

async function get_section_menu(section,raw_menu){
Expand Down
3 changes: 2 additions & 1 deletion src/components/markdown/code/DiagramCode.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import Highlighter from './Highlighter.astro'
import Panzoom from '@/components/panzoom/panzoom.astro'
import { config } from '@/config.js';
export interface Props {
hash:string;
Expand All @@ -9,7 +10,7 @@ export interface Props {
}
const {hash, code, params} = Astro.props as Props;
const diagram_url = `/codes/${hash}/diagram.svg`
const diagram_url = `${config.base}/codes/${hash}/diagram.svg`
let alt = ""
let title = ""
if(params && (params.length > 0)){
Expand Down
3 changes: 2 additions & 1 deletion src/components/markdown/code/Highlighter.astro
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ pre{
</style>

<script>
import {config} from '@/client_config.js'
const buttons = document.querySelectorAll('button.copy-btn');
buttons.forEach(button => {
button.addEventListener('click', async () => {
const hash = button.getAttribute('data-hash');
const message = document.querySelector(`.copy-message[data-hash="${hash}"]`);

try {
const response = await fetch(`/codes/${hash}/code.txt`);
const response = await fetch(`${config.base}/codes/${hash}/code.txt`);
if (response.ok) {
const codeText = await response.text();
await navigator.clipboard.writeText(codeText);
Expand Down
9 changes: 2 additions & 7 deletions src/components/markdown/code/LinkCode.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
---
import Highlighter from './Highlighter.astro'
import Kroki from './Kroki.astro'
import ModelViewerCode from '../model/ModelViewerCode.astro';
import Cards from '../cards/Cards.astro'
import Gallery from '../../gallery/gallery.astro';
import Swiper from '../../swiper/swiper.astro'
import kroki from './kroki.yaml'
import {join,dirname} from 'path'
import {join} from 'path'
import {config} from '@/config.js'
import {constants, access, mkdir, readFile, writeFile} from 'fs/promises'
import {readFile} from 'fs/promises'
export interface Props {
ext: string;
Expand Down
31 changes: 23 additions & 8 deletions src/components/panzoom/panzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ function fixSvgSize(svg){

svg.setAttribute('width', width);
svg.setAttribute('height', height);
console.log("fixed SVG width and heigh")
}else{
console.log("no viewBox")
}
}
}
}else{
console.log("failed to fix svg size as svg is invalid")
}
}

async function add_links(svg,url_map){
Expand Down Expand Up @@ -52,6 +57,15 @@ function checkModal(){
}
}

function processSVG(svg,container){
fixSvgSize(svg);
const url_map_string = container.getAttribute("data-url-map");
if(url_map_string){
const url_map = JSON.parse(url_map_string);
add_links(svg, url_map);
}
}

function init(){
const containers_els = document.querySelectorAll(".container.panzoom")
if(containers_els.length == 0){//prevent irrelvant page execution
Expand All @@ -63,15 +77,16 @@ function init(){
const eltype = container.getAttribute("data-type")
if(eltype == "svg"){
const obj = container.querySelector("object")
const svg = obj.contentDocument.querySelector("svg")
fixSvgSize(svg)
const url_map_string = container.getAttribute("data-url-map")
if(url_map_string){
const url_map = JSON.parse(url_map_string)
add_links(svg,url_map)
const svg = obj.contentDocument.querySelector("svg");
if(svg){
processSVG(svg,container)
}else{
obj.addEventListener("load", () => {
const svg = obj.contentDocument.querySelector("svg");
processSVG(svg,container)
});
}
}

const open = container.querySelector(".open")
open.onclick = ()=>{
const modal = container.querySelector(".modal-background")
Expand Down
2 changes: 1 addition & 1 deletion src/libs/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function add_base(url){
}

function remove_base(pathname){
if(pathname.startsWith(config.base)){
if((config.base != "") && (pathname.startsWith(config.base))){
pathname = pathname.substring(config.base.length)
}
return pathname
Expand Down
2 changes: 1 addition & 1 deletion src/libs/client_utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {config} from '@/client_config.js'

function remove_base(pathname){
if(pathname.startsWith(config.base)){
if((config.base != "") && (pathname.startsWith(config.base))){
pathname = pathname.substring(config.base.length)
}
return pathname
Expand Down

0 comments on commit adf70d7

Please sign in to comment.